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
josephmwood
Regular Visitor

Comparing years in line graph

I saw a previous message that was similar to this, but I could not figure out how to get the answer to work at all.

 

I have a dashboard I have made in Excel using a pivot chart from a pivot table. It tracks attendance at a weekly event for the last few years. I have slicers set up to allow people to compare year over year. It's so simple to just click a year and it overlays right on top of the current year.

 

I can't figure out how to do that in PowerBI. I've seen at least 5 different people all give different solutions on different forums, but I can't get any of them to work for me.

11 REPLIES 11
FrankAT
Community Champion
Community Champion

Hi @josephmwood ,

take a look at the attached PBIX file.

 

19-05-_2021_23-02-32.png

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

 

DAX measures are an option I guess but it should be noted that this is not a very dynamic solution as a new measure would need to be added every year. 

Also, I think the X axis having year included is misleading in this scenario.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
josephmwood
Regular Visitor

Screen Shot 2021-05-19 at 3.00.29 PM.png

 

Here's what my dashboard looks like in excel. I'll upload a spreadsheet with most of the data that I'm wanting to use. I'm actually connecting to a SQL Server for PowerBI, but the data is the same (I'm looking at moving this dashbaord to a PowerBI site that people can check on their phone).


Let me know if this is enough data.

 

DateVenue TypeServiceVenueTotal
Sunday, May 16, 2021Combined TotalAll ServicesAll Venues Total1336
Sunday, May 9, 2021Combined TotalAll ServicesAll Venues Total1381
Sunday, May 17, 2020Combined TotalAll ServicesAll Venues Total90
Sunday, May 10, 2020Combined TotalAll ServicesAll Venues Total104
Sunday, May 19, 2019Combined TotalAll ServicesAll Venues Total2583
Sunday, May 12, 2019Combined TotalAll ServicesAll Venues Total2653

Thanks for that.

With a couple of steps, that data, looks like this...

 

image.png

 

The important part, add a new column for 'year' (for your legend), and add a new column for your X axis, I did week of year but you can adapt to your needs.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7NS0ms1FHwTaxUMDTTUTAyMDJU0lFyzs9NysxLTVEIyS9JzAEKOObkKASnFpVlJqcWQ7lhqXmlqcVwFYbGxmZKsTqoRlpSZqKFIYaJhuZgIw3IM9LSANNAA0oMNDQwwTQR7GtDS/JMNDK1MMY00ogiI81MgUbGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Venue Type" = _t, Service = _t, Venue = _t, Total = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Venue Type", type text}, {"Service", type text}, {"Venue", type text}, {"Total", Int64.Type}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
    #"Inserted Week of Year" = Table.AddColumn(#"Inserted Year", "Week of Year", each Date.WeekOfYear([Date]), Int64.Type)
in
    #"Inserted Week of Year"

 

Hope this helps.

 

Regards,

Kim

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

I appreciate the quick response Kim!

Unfortunately I'm a complete noob to PowerBI and that code makes zero sense to me and I would have absolutely no idea how to implement it in my PowerBI dashboard that I have connected to my SQL server. Is there anyway you could explain it a bit clearer to me? I'm not in a hurry at all. Thanks so much!

I understand. To use my sample code follow the below steps.

 

 

Go to Transform data.

 

image.png

 

 

 

 

 

 

 

Right click in a blank area in the query pane and select New Query --> Blank Query

KNP_0-1621456838333.png

 

With the query selected, choose Advanced Editor

KNP_1-1621456932031.png

 

 

Paste my code over what is there and click done.

KNP_2-1621457020033.png

 

You'll then be able to see the steps I followed.

 

Essentially, all you're trying to do is add a column for year for the legend and one for a date part of some kind that excludes year (I used week number) for the X axis.

 

What you end up with is...

KNP_3-1621457326812.png

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

Thanks so much! 

 

I did this on my table and it created the new queries and i see them, but they have no effect on my table right now. I tried creating relationships between the date and my tables, but it doesn't do anything. Do I have to customize your code to fit with my tables and correct column names that I'm pulling from my server? I'm using several different sections of a server to bring information together.

I only included that query to serve as an example of how I'd approach it so you could see the individual steps. Sorry, I may not have explained that well. 

 

What you need is a 'year' (in your date dimension if you have one) for the legend and something for your X axis like week number. 

Are you able to attach a screen shot of your model showing the joins? I might be able to offer better advice if I can see the data model.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

I appreciate you helping me out!

Here's a screenshot of the settings for my current line graph. Screen Shot 2021-05-26 at 11.17.18 AM.png

 

Let me know if that helps at all.

It's the screenshot of the model that would be most helpful. (and probably the graph)

KNP_0-1622055607105.png

 

How does the Power BI version of the graph look right now?

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
KNP
Super User
Super User

Hi @josephmwood - some screenshots of desired outcome and some sample data will help get this answered much quicker. (read post by @Greg_Deckler: https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523#M6071...)

 

Sounds super easy. I'll be happy to help with some more info.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

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.