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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
IvanCM
Frequent Visitor

Duplicate table with every combination based on a specific column

I have an exisiting table where I need to populate missing rows with no values as per the Current and Required table example below...

Basically, for every entry, there should be every version of the "Timesheet" column, e.g. if only an "Actuals" value exists in the current table, I need the missing row for "Planned" to exist.

 

Current Table vs Required Table.JPG

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@IvanCM 

 

Try this.

Pivot the Timesheet Column using Hours as values ("Dont Aggregate")

replace nulls with zero

Unpivot the Actuals and planned columns

 

Please see attached file for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDU9UrM0zW0VNJRcgTh5JLSxJxiIMtCKVYHUz4gJzEvLzUFyLKEyBsh5J1Q9BsaYBjgTMACZ3QLYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Timesheet = _t, Hours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Timesheet", type text}, {"Hours", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Timesheet]), "Timesheet", "Hours"),
    #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"Planned"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Date", "Name"}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@IvanCM 

 

Try this.

Pivot the Timesheet Column using Hours as values ("Dont Aggregate")

replace nulls with zero

Unpivot the Actuals and planned columns

 

Please see attached file for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDU9UrM0zW0VNJRcgTh5JLSxJxiIMtCKVYHUz4gJzEvLzUFyLKEyBsh5J1Q9BsaYBjgTMACZ3QLYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Timesheet = _t, Hours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Timesheet", type text}, {"Hours", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Timesheet]), "Timesheet", "Hours"),
    #"Replaced Value" = Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,{"Planned"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Date", "Name"}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Regards
Zubair

Please try my custom visuals

Worked exactly as I wanted!

 

Thanks @Zubair_Muhammad

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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