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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Riddlemirror
Frequent Visitor

Displaying Month Data side by side

Hi Team,

I have a set of certain metrics with Actual Values in one column and Target Values in second column, for every month. 
I cannot figure out how to display those 2 values for each corresponding month side by side.  For example: Target and Actual for April should be in one row. 

Screenshot 2022-03-15 104026.jpg

1 ACCEPTED SOLUTION
Thejeswar
Resident Rockstar
Resident Rockstar

Hi @Riddlemirror  ,

You need to perform the below steps to transform the table as per your expectation.

1. Unpivot the Actual and Target Columns

2. Filter the value column to exclude nulls

3. Pivot the Attribute column with Value column to be selected as value. You will have to change the aggregation from count to Max post this step

Source:

Thejeswar_2-1647340381693.png

 

Target:

 Thejeswar_0-1647340168481.png

Insead use the below M Query to get this

 

let
    Source,
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Month"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> "null")),
    #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Attribute]), "Attribute", "Value", List.Max)
in
    #"Pivoted Column"

 

 Replace Source with your source details in the above M code

Regards,

 

 

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Riddlemirror , if you are sure there is only one value per month, use group by and take the max of both columns

https://docs.microsoft.com/en-us/power-query/group-by

Thejeswar
Resident Rockstar
Resident Rockstar

Hi @Riddlemirror  ,

You need to perform the below steps to transform the table as per your expectation.

1. Unpivot the Actual and Target Columns

2. Filter the value column to exclude nulls

3. Pivot the Attribute column with Value column to be selected as value. You will have to change the aggregation from count to Max post this step

Source:

Thejeswar_2-1647340381693.png

 

Target:

 Thejeswar_0-1647340168481.png

Insead use the below M Query to get this

 

let
    Source,
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Month"}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each ([Value] <> "null")),
    #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Attribute]), "Attribute", "Value", List.Max)
in
    #"Pivoted Column"

 

 Replace Source with your source details in the above M code

Regards,

 

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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