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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

 

View solution in original post

v-tangjie-msft
Community Support
Community Support

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
v-tangjie-msft
Community Support
Community Support

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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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