Skip to main content

Notifications

Power Automate - General Discussion
Unanswered

Dynamically Create an HTML Table with Child Table for Repeated Employee Names in Power Automate?

(0) ShareShare
ReportReport
Posted on by 4
I am working on a Power Automate flow where I need to dynamically create an HTML table based on employee data. The table should have a separate row for each employee. If the employee name is repeated, I want to append their data into the last row of the repeated employee instead of creating a new row each time. Additionally, after the last row for each employee, I need to insert a child table with dynamic values.

I am trying to create a output liek this
, 

the approach I have tied to create table


the output I have now,


No I want to insert the new child html below content after each employee row ,I mean last row 
Categories:
  • Chriddle Profile Picture
    Chriddle 7,206 on at
    Dynamically Create an HTML Table with Child Table for Repeated Employee Names in Power Automate?
    If you preffer to create the HTML yourself, you can do something like this:
     
    Select 2
    From:
    range(0, length(sort(outputs('Compose'), 'Name')))
    Map:
    if(
    	or(
    		equals(item(), 0),
    		not(
    			equals(
    				sort(outputs('Compose'), 'Name')[sub(item(), 1)].Name,
    				sort(outputs('Compose'), 'Name')[item()].Name
    			)
    		)
    	),
    	concat(
    		'<tr class="namerow"><td rowspan="',
    		length(
    			xpath(
    				xml(json(concat('{"Root":{"Item":',outputs('Compose'),'}}'))),
    				concat('//Item[Name="',sort(outputs('Compose'), 'Name')[item()].Name,'"]')
    			)
    		),
    		'">',
    		sort(outputs('Compose'), 'Name')[item()].Name,
    		'</td><td>',
    		sort(outputs('Compose'), 'Name')[item()].Value0,
    		'</td><td>',
    		sort(outputs('Compose'), 'Name')[item()].Value1,
    		'</td></tr>'
    	),
    	concat(
    		'<tr><td>',
    		sort(outputs('Compose'), 'Name')[item()].Value0,
    		'</td><td>',
    		sort(outputs('Compose'), 'Name')[item()].Value1,
    		'</td></tr>'
    	)
    )
    Compose 2
    join(body('Select_2'), '')
     
     
  • POWERCOIN_USER Profile Picture
    POWERCOIN_USER 4 on at
    Dynamically Create an HTML Table with Child Table for Repeated Employee Names in Power Automate?
    Thanks for your reply.I see this output 
    The resulting table needs some additional styles to look great ;)
     
     
    I got same out put but My request is here to insert this child table mentioend below in each Name's under ..Like Jane records after 10,11 I need this child table and After jim's row 20,21 i eed to this child table value and I need to check this Name has child records based on the date And I need to insert it.

  • Chriddle Profile Picture
    Chriddle 7,206 on at
    Dynamically Create an HTML Table with Child Table for Repeated Employee Names in Power Automate?
    A similar approach with the same result as below (but a bit more compact)
     
    Create HTML table
    sort(outputs('Compose'), 'Name')
    Select
    From:
    range(0, length(split(body('Create_HTML_table'), '<tr>')))
     
     
    Map:
    if(
    	less(item(), 2),
    	split(body('Create_HTML_table'), '<tr>')[item()],
    	if(
    		startswith(
    			split(body('Create_HTML_table'), '<tr>')[sub(item(), 1)],
    			slice(
    				split(body('Create_HTML_table'), '<tr>')[item()],
    				0,
    				add(
    					indexOf(
    						split(body('Create_HTML_table'), '<tr>')[item()],
    						'</td>'
    					),
    					5
    				)
    			)
    		),
    		slice(
    			split(body('Create_HTML_table'), '<tr>')[item()],
    			add(
    				indexOf(
    					split(body('Create_HTML_table'), '<tr>')[item()],
    					'</td>'
    				),
    				5
    			)
    		),
    		concat(
    			'<td rowspan="',
    			
    			length(
    				xpath(
    					xml(json(concat('{"Root":{"Item":',outputs('Compose'),'}}'))),
    					concat('//Item[Name="',
    					slice(
    						split(body('Create_HTML_table'), '<tr>')[item()],
    						4,
    						indexOf(
    							split(body('Create_HTML_table'), '<tr>')[item()],
    							'</td>'
    						)
    					),
    					'"]')
    				)
    			),
    			
    			'">',
    			slice(
    				split(body('Create_HTML_table'), '<tr>')[item()],
    				4
    			)
    		)
    	)
    )
     
    Compose 4
    replace(
    	join(body('Select'), '<tr>'),
    	'<tr><td rowspan',
    	'<tr class="namerow"><td rowspan'
    )
     
  • Chriddle Profile Picture
    Chriddle 7,206 on at
    Dynamically Create an HTML Table with Child Table for Repeated Employee Names in Power Automate?
    Instead of creating a custom HTML table, you use the "Create HTML table" action and modify its output.
     
    Here an example creating such a table from following example data:
    [
    {"Name":"Jim", "Value0": 0, "Value1": 1},
    {"Name":"John", "Value0": 0, "Value1": 0},
    {"Name":"Jim", "Value0": 10, "Value1": 11},
    {"Name":"Jane", "Value0": 0, "Value1": 1},
    {"Name":"Jane", "Value0": 10, "Value1": 11},
    {"Name":"Jim", "Value0": 20, "Value1": 21}
    ]
     
     
    From the array (sorted by Name) in a Compose, Create HTML table
     
    Initialize variable with this HTML
     
    Apply to each distinct Name
    union(
    	xpath(
    		xml(json(concat('{"Root":{"Item":',outputs('Compose'),'}}'))),
    		'//Item/Name/text()'
    	),
    	json('[]')
    )
     
    In a Compose 2, find the first occurence of the td with the Name and add a rowspan to it. The value is the count of this Name in the data array.
    Also add a CSS class to the tr.
    remove the td with this Name from the rest of the table.
    concat(
    	replace(
    		slice(
    			variables('htmlTable'),
    			0,
    			nthIndexOf(
    					variables('htmlTable'),
    					concat('<tr><td>',items('Apply_to_each'),'</td>'),
    					2
    				)
    		),
    		concat('<tr><td>',items('Apply_to_each'),'</td>'),
    		concat('<tr class="namerow"><td rowspan="',
    			length(
    				xpath(
    					xml(json(concat('{"Root":{"Item":',outputs('Compose'),'}}'))),
    					concat('//Item[Name="',items('Apply_to_each'),'"]')
    				)
    			),
    		'">',items('Apply_to_each'),'</td>')
    	),
    	replace(
    		slice(
    			variables('htmlTable'),
    			nthIndexOf(
    				variables('htmlTable'),
    				concat('<tr><td>',items('Apply_to_each'),'</td>'),
    				2
    			)
    		),
    		concat('<tr><td>',items('Apply_to_each'),'</td>'),
    		'<tr>'
    	)
    )
    Use Set variable store the output of Compose 2
     
    After the loop, add some styles to the HTML in Compose 3
     
     
     
    The resulting table needs some additional styles to look great ;)
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

End of Year Newsletter…

End of Year Community Newsletter…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #11 New Opportunities…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,609

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,420

Leaderboard