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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
iwhite01
Regular Visitor

Changing rows and columns and "grouping" them

I am trying to make a visual that will show specific dates and reporting metrics in one table/matrix but I cannot get it to work through any PowerBI features.

 

My data is connected to a Microsoft list. The data ends up looking like this (extremely simplified):

 

SiteDate 1Date 2Date 3Target 1Target 2Target 3Metric 1Metric 2Metric 3
ADate 1ADate 2ADate 3ATarget 1ATarget 2ATarget 3AMetric 1AMetric 2AMetric 3A
BDate 1BDate 2BDate 3BTarget 1BTarget 2BTarget 3BMetric 1BMetric 2BMetric 3B
CDate 1CDate 2CDate 3CTarget 1CTarget 2CTarget 3CMetric 1CMetric 2CMetric 3C

 

The date and the target columns are dates and the metric column is a customn column calculation that is a whole number (days between two dates). 

 

I would like to have the data display in a visual like this:

 

 DatesTargetsMetric
Site ADate 1ATarget 1AMetric 1A
 Date 2ATarget 2AMetric 2A
 Date 3ATarget 3AMetric 3A

 

Where you select the site and the associated dates, targets, and metrics are broken down into columns.

 

The closest I can get is by piecing together multiple matrix's and blanking out left column.

iwhite01_2-1750706999245.png

Please let me know if there is anything I can do to make this work. 

 

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

In the first table that you have shared, please fill up entries under the columns for us to know the data type under each column.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

The date column is dates, the target column is a date custom column that adds days to the initial date column, and the metric column is custom column that is a whole number representing the number of days between the two dates.

Hi,

Use this M code

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Site"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Site", type text}, {"Date ", type date}, {"Target ", type date}, {"Metric ", Int64.Type}})
in
    #"Changed Type"

Hope this helps.

Ashish_Mathur_0-1750808553984.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Unpivot your data and then re-pivot part of it

lbendlin_0-1750714623683.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc07CsAgFETRrQRrm4wriKZNl04sJEhIK+6f+H1Md2AGrvfqUFqdsaRtF0Fkmu6Y31TGPg1y/1yp5O8Zn2mQ6ydor6y0RBAZSy0yyP2zWmSQ66e1nLREEBlHLTLI/bNaZJDrJ4Qf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Site = _t, #"Date 1" = _t, #"Date 2" = _t, #"Date 3" = _t, #"Target 1" = _t, #"Target 2" = _t, #"Target 3" = _t, #"Metric 1" = _t, #"Metric 2" = _t, #"Metric 3" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Site"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute", "Row"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

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". Once you examined the code, replace the entire Source step with your own source.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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