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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Columns to rows

Hi,

 

I have read many articles and tutorials. Also searched on this forum to find a solution for my problem. Unfortunately, couldnt find it.

 

Basically, my data source looks like below 

am70_0-1637770884822.png

The outcome should look like this:

am70_2-1637772451971.png

 

The way I managed to produce above was creating 2 queries referencing the source (query 1 - filtered 2019 and query 2 - filtered 2020) then created additional query to merge the referecing queries. Here is the the code: 

 

let
Source = #"Ref 2020",
#"Removed Columns" = Table.RemoveColumns(Source,{"Year", "Impression", "cost "}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Campaign"}, #"Ref 2019", {"Campaign"}, "Ref 2019", JoinKind.LeftOuter),
#"Expanded Ref 2019" = Table.ExpandTableColumn(#"Merged Queries", "Ref 2019", {"Impression", "cost "}, {"Ref 2019.Impression", "Ref 2019.cost "}),
#"Merged Queries1" = Table.NestedJoin(#"Expanded Ref 2019", {"Campaign"}, #"Ref 2020", {"Campaign"}, "Ref 2020", JoinKind.LeftOuter),
#"Expanded Ref 2020" = Table.ExpandTableColumn(#"Merged Queries1", "Ref 2020", {"Impression", "cost "}, {"Ref 2020.Impression", "Ref 2020.cost "})
in
#"Expanded Ref 2020"

 

The problem with above method is uncessary creating multiple queries which is not ideal in terms of refreshing times. I tried to upload the file but didnt support it.

 

I really hope you can help me with this! Many thanks.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You can create a matrix visual and display it with year on the column, campaign on row, impression, and cost on values 

 

If you need a table.

1. Unpivot Cost and impression

2. Concat year and category column in new measure name and remove the two {year, measure name}

header = [Year] & "." &[Measure name]

3 then pivot header and value 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You can create a matrix visual and display it with year on the column, campaign on row, impression, and cost on values 

 

If you need a table.

1. Unpivot Cost and impression

2. Concat year and category column in new measure name and remove the two {year, measure name}

header = [Year] & "." &[Measure name]

3 then pivot header and value 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you so much for your help. I tried it and it works. You are a legend.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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