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
Anonymous
Not applicable

Creating sub columns in power dashboard

Hello Community,

 

 

 

 

 

I am trying to build a table/matrix in power bi dashboard which looks as below, anyone who can help me with that?

 

 

Columns.PNG

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

that's why I wrote that you have to filter out Total Products sold in step 1), otherwise it will be duplicated
create a new query in the Query Editor, go to advanced editor and paste this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kpMzlbSUTI0NTAwANJGFiCOAVgESBiDGBYgqVidaCXfzOxUkBoDiFpjI5gyQxALxDAygqkNygQbawQ1FqwKbJohiABiiKmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Person" = _t, Sales = _t, #"Total Products sold" = _t, Jeans = _t, Shirts = _t, Jackets = _t, #"Target Sales" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Person", type text}, {"Sales", Int64.Type}, {"Total Products sold", Int64.Type}, {"Jeans", Int64.Type}, {"Shirts", Int64.Type}, {"Jackets", Int64.Type}, {"Target Sales", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Sales Person"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Attribute] <> "Total Products sold")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "L1", each if ([Attribute] = "Jeans" or [Attribute] = "Shirts" or [Attribute] = "Jackets") then "Total Product sold" else [Attribute]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "L2", each if [L1] = "Total Product sold" then [Attribute] else ""),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Attribute"})
in
    #"Removed Columns"

it will produce table like this
Capture.PNGCapture.PNG

which you can turn into requested visual



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

5 REPLIES 5
Stachu
Community Champion
Community Champion

I think this functionality is still in the ideas:
https://ideas.powerbi.com/forums/265200/suggestions/36038050
you could achive something similar with Matrix visual if the columns you show would look like this

Sales Person 
Sales Person 
Product SoldJeans
Product SoldShirts
Product SoldJackets
Target 

I guess the second column is populated for all, but you could create a new column just for this purpose - not an elegant solution, but may work



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Hello Stachu,

 

I tried several things with matrix, but it couldn't give the desired result as mentioned above. The actual table looks like this;

 

 

Table.PNG

Stachu
Community Champion
Community Champion

you need to modify the source then, right now there is no indication at all which elements are a sub group of what
I thuoght you actually have a proper hierarchy there, then Unpivot in the Query editor would solve this

with this format I think you can do following:
1) unpivot all so the labels are in rows, filter out Total Products sold:

2) add custom column that would say "Total Products sold" for Jeans, Shirts and Jackets and else whatever is in the original column
3) add custom column that would just be  Jeans, Shirts and Jackets and else empty
4) put the column from 2 &3 in the columns for the matrix visual, and the Value column in Values

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Tried unpivot earlier as well, but couldn't get the exact matrix that I am looking for. if I populate then it gives more details about the total product sales and product types etc but thats not my requirement.

 

sample data

Table.PNG

 

Stachu
Community Champion
Community Champion

that's why I wrote that you have to filter out Total Products sold in step 1), otherwise it will be duplicated
create a new query in the Query Editor, go to advanced editor and paste this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kpMzlbSUTI0NTAwANJGFiCOAVgESBiDGBYgqVidaCXfzOxUkBoDiFpjI5gyQxALxDAygqkNygQbawQ1FqwKbJohiABiiKmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Person" = _t, Sales = _t, #"Total Products sold" = _t, Jeans = _t, Shirts = _t, Jackets = _t, #"Target Sales" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Person", type text}, {"Sales", Int64.Type}, {"Total Products sold", Int64.Type}, {"Jeans", Int64.Type}, {"Shirts", Int64.Type}, {"Jackets", Int64.Type}, {"Target Sales", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Sales Person"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each ([Attribute] <> "Total Products sold")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "L1", each if ([Attribute] = "Jeans" or [Attribute] = "Shirts" or [Attribute] = "Jackets") then "Total Product sold" else [Attribute]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "L2", each if [L1] = "Total Product sold" then [Attribute] else ""),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Attribute"})
in
    #"Removed Columns"

it will produce table like this
Capture.PNGCapture.PNG

which you can turn into requested visual



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.