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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
BeccaD
New Member

Multiple headers on some columns based on column title prefix

Hi,

Very new to Power BI here, so please bare with me.

 

I am trying to build a report with a table visual based upon some data from SQL Server.

 

I have a table that looks similar to this:

 

BeccaD_0-1639992466395.png

 

And I need to present it more like this:

 

BeccaD_1-1639992538501.png

Is there a way to achieve this? All the examples I have seen on here seem to be based on Excel data and pivot tables, but I'm not really sure that applies in this instance.

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @BeccaD ,


1.Add a Index column:

Eyelyn9_0-1640239785486.png

 

2. Click Index column, select "Unpivot other columns":

Eyelyn9_1-1640239857490.png

 

3. Click Attribute column, split it by "-":

Eyelyn9_2-1640239913769.png

 

4. Rename columns.

Eyelyn9_3-1640239973979.png

 

Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoC4mQgTgHiVCBOU4rViVZKB7IygDgHiDOBOAuIs5ViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, #"columnPrefix1-Column3" = _t, #"columnPrefix1-Column4" = _t, #"columnPrefix2-Column5" = _t, #"columnPrefix2-Column6" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"columnPrefix1-Column3", type text}, {"columnPrefix1-Column4", type text}, {"columnPrefix2-Column5", type text}, {"columnPrefix2-Column6", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Attribute.1", "Level1"}, {"Attribute.2", "Level2"}})
in
    #"Renamed Columns"

 

 5. Create a Matrix visual as shown below:

Eyelyn9_4-1640240023621.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @BeccaD ,


1.Add a Index column:

Eyelyn9_0-1640239785486.png

 

2. Click Index column, select "Unpivot other columns":

Eyelyn9_1-1640239857490.png

 

3. Click Attribute column, split it by "-":

Eyelyn9_2-1640239913769.png

 

4. Rename columns.

Eyelyn9_3-1640239973979.png

 

Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoC4mQgTgHiVCBOU4rViVZKB7IygDgHiDOBOAuIs5ViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, #"columnPrefix1-Column3" = _t, #"columnPrefix1-Column4" = _t, #"columnPrefix2-Column5" = _t, #"columnPrefix2-Column6" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"columnPrefix1-Column3", type text}, {"columnPrefix1-Column4", type text}, {"columnPrefix2-Column5", type text}, {"columnPrefix2-Column6", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Attribute.1", "Level1"}, {"Attribute.2", "Level2"}})
in
    #"Renamed Columns"

 

 5. Create a Matrix visual as shown below:

Eyelyn9_4-1640240023621.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@BeccaD , You might have to unpivot the columns and split that. Or dynamic segmentation

 

refer

column header grouping
https://www.daxpatterns.com/dynamic-segmentation/
https://community.powerbi.com/t5/Desktop/Matrix-Display-Values-above-Columns/td-p/256905
https://community.powerbi.com/t5/Desktop/grouping-measure-results/td-p/456795

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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