Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JVos
Helper IV
Helper IV

Insert empty row without explicitly specifying column names

For adding one empty row to the "Sorted rows" intermediate result I have the following code:

 

Table.InsertRows(#"Sorted Rows", 0, {[RoutingCropGroupCode = "", RouteName = "", LineNumber = "", Percentage = "", Quantity = "", DisplaySequence = "", CheckUniqueness = "", CheckPercentage = "", CheckRCGRouteMaster = ""]})

 

However, when there will be a change in the source columns, the code is broken. How can I add the columns dynamically?

 

Probably it's something with Table.ColumnNames(#"Sorted Rows"), but this will only return the column names. How then to add the empty values?

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@JVos 

 

Also this one.

This uses your Table.InsertRows method

 

= Table.InsertRows(#"Sorted Rows", 0,{Record.FromList(List.Repeat({""},Table.ColumnCount(#"Sorted Rows")),Table.ColumnNames(#"Sorted Rows"))})

Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

ChatGPT told me to use this. It is simple and it works.

 

Table.Combine( { Table.FromRecords( { [ ] } ), NormalTable } ) 

 

Expression "Table.FromRecords( { [ ] } )" will return table with 1 row and zero columns (!!!).  After union, no new columns will be added to "NormalTable" because they don't exist, but one row will be added. That one row will be filled with nulls, as it is normal behavior for Table.Combine function. Super clever.

Zubair_Muhammad
Community Champion
Community Champion

@JVos 

 

Also this one.

This uses your Table.InsertRows method

 

= Table.InsertRows(#"Sorted Rows", 0,{Record.FromList(List.Repeat({""},Table.ColumnCount(#"Sorted Rows")),Table.ColumnNames(#"Sorted Rows"))})

Regards
Zubair

Please try my custom visuals

Just to add that this won't create a truly empty row - it inserts "" and should instead use

List.Repeat(null)

 

@Zubair_Muhammad: Works perfectly, thank you!

Zubair_Muhammad
Community Champion
Community Champion

@JVos 

 

Try this alternative

 

Table.Combine({
Table.FromColumns(List.Transform(List.Repeat({""},Table.ColumnCount(#"Sorted Rows")),each {_}),Table.ColumnNames(#"Sorted Rows")),
#"Sorted Rows"})

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors