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
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
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.