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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
dswallow
Helper I
Helper I

Create line graph to compare sales per region per year

I would like to create a line graph using an excel data source. The issue is the excel has seperate columns for each year and therefore I do not know an easy way to use these seperate fields in one line graph. I have attached a screenshot of the data below:

 

We also have a field for the average ages of buyers for that region. 

 

dswallow_0-1675347914975.png

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@dswallow , Unpivot the data in the power query.

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

 

If need you can take a year as a legend in the line visual post that

 

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

Anonymous
Not applicable

Hi @dswallow ,

 

According to your description, here are my steps you can follow as a solution.

(1)  My test data is the same as yours.

(2)  Click "Transform Data" to enter the Power Query editor and select three columns to transpose.

Picture1.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEK9QYSJkBsqoqFEasTrWQOZLqWFuUXpAIZxkBspoqFAVJpBGQGOwIJI5gx6AyQKkOQrWBlIK3mIFlDNEZsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Avg <5>" = _t, Region = _t, #"2022" = _t, #"2022%" = _t, #"2021" = _t, #"2021%" = _t, #"2020" = _t, #"2020%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Avg <5>", Int64.Type}, {"Region", type text}, {"2022", Int64.Type}, {"2022%", Percentage.Type}, {"2021", Int64.Type}, {"2021%", Percentage.Type}, {"2020", Int64.Type}, {"2020%", Percentage.Type}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"2022", "2021", "2020"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Only Selected Columns",{{"Attribute", "Year"}, {"Value", "Sales"}})
in
    #"Renamed Columns"

 

(3) Then the result is as follows.

vtangjiemsft_0-1675654774490.png

 

 

Best Regards,

Neeko Tang

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
Anonymous
Not applicable

Hi @dswallow ,

 

According to your description, here are my steps you can follow as a solution.

(1)  My test data is the same as yours.

(2)  Click "Transform Data" to enter the Power Query editor and select three columns to transpose.

Picture1.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEK9QYSJkBsqoqFEasTrWQOZLqWFuUXpAIZxkBspoqFAVJpBGQGOwIJI5gx6AyQKkOQrWBlIK3mIFlDNEZsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Avg <5>" = _t, Region = _t, #"2022" = _t, #"2022%" = _t, #"2021" = _t, #"2021%" = _t, #"2020" = _t, #"2020%" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Avg <5>", Int64.Type}, {"Region", type text}, {"2022", Int64.Type}, {"2022%", Percentage.Type}, {"2021", Int64.Type}, {"2021%", Percentage.Type}, {"2020", Int64.Type}, {"2020%", Percentage.Type}}),
    #"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type", {"2022", "2021", "2020"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Only Selected Columns",{{"Attribute", "Year"}, {"Value", "Sales"}})
in
    #"Renamed Columns"

 

(3) Then the result is as follows.

vtangjiemsft_0-1675654774490.png

 

 

Best Regards,

Neeko Tang

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

@dswallow , Unpivot the data in the power query.

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

 

If need you can take a year as a legend in the line visual post that

 

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.