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
LazarosC
Frequent Visitor

Hierarchy horizontal expand on a table.

Hello everybody

 

I get the usuall expand option in the table with the +/- symbol. Whenever i press it all the components of the specific hierarchy
expand as they should.

What i want to do is, instead of a vertical expanding, to get an horizontal expanding with every row containing the city that belongs to the corresponding cluster. Below there's a screenshot of an excel file showing the final result.

 

Each row should contain only the cities that are in the specific cluster, in the same way that each column contains only the related cities.

 

LazarosC_0-1669991505906.png

 

Hopefully i provided every useful information.

 

Any help is highly appreciated.

 

Thank you for your time

Kind Regards

Lazaros

 

1 ACCEPTED SOLUTION

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWJVnICsozALJCYCZjlDGQZg1kuQJYpnGUGZrmC9EK0uAGZFmCWB0jQAC5oiRAEWhMLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, Product = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Region"}, {{"Count", each _, type table [Region=nullable text, Product=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Products", each Text.Combine([Count][Product],",")),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Region", "Products"})
in
    #"Removed Other Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

I get the usuall expand option in the table with the +/- symbol.

No, the table doesn't have that option.  You mean the matrix visual?

 

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Thank you very much for replying.

Sorry that i didnt explain it clearly, yes i meant the option from the matrix visual indeed. Where you can choose to expand it and you get the vertical expanding.

Bellow i will post some simplyfied data that show the issue i have.

RegionProduct 
A1
B2
C3
D5
A4
B2
C3
D5
E2


The expected outcome should look like this. 

LazarosC_0-1670156624331.png

Each row needs to show only the products that fall into the corresponding region, 1 or more products.

 

On the picture i posted on the original thread, that was achieved verticaly in power bi with the expand option that is available in the matrix visual (+/- symbol). I try to find a way to achieve it with horizontaly view.

 

Both Region and products are in the same table.

Can this be achieved by measure or there's another way?

Hopefully i provided all the information needed to make it clear.

Thank you very much for your time.

Cheers


Please show the expected outcome based on the sample data you provided.

Hello, 

 

I will reprovide the sample data and then the desired outcome based on the exact sample data.

 

RegionProduct
A1
B2
Α4
C3
D5
D6
E12
F8
H10
F9
H11

 

And the expected outsome should look like this

 

LazarosC_1-1670227049201.png

 

Each region may contain more than one products, and each product is uniquely matched only in 1 region.

 

Hope this one helps

 

Thank you very much

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJUitWJVnICsozALJCYCZjlDGQZg1kuQJYpnGUGZrmC9EK0uAGZFmCWB0jQAC5oiRAEWhMLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, Product = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Region"}, {{"Count", each _, type table [Region=nullable text, Product=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Products", each Text.Combine([Count][Product],",")),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Region", "Products"})
in
    #"Removed Other Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thank you very much for your help.

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