Reply
avatar user
Anonymous
Not applicable
Partially syndicated - Outbound

How to show only 2 years in pie chart

Hi everyone,

 

I need a little help.

 

I have a pie chart where I have data for 2019, 2020 and 2021, but I'd like to return only the last 2 years based on the selected value in my slicer.

 

For example, if I have selected 2020 in my slicer, it would show 2019 and 2020. If I select 2021, it would show me 2020 and 2021, always considering the same period last year.

 

But I'm having trouble to do that.

 

The chart considers only my dCalendar[Year] and a simple measurement for counting: count = DISTINCTCOUNT (Table [Incident]).

vmzandonadi_0-1611592226795.png

 

Could anyone help me with this?

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

Syndicated - Outbound

@Anonymous solution attached, hope this is what you are looking for, see image below

 

pie chart current and previous year.gif

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

10 REPLIES 10
parry2k
Super User
Super User

Syndicated - Outbound

@Anonymous solution attached, hope this is what you are looking for, see image below

 

pie chart current and previous year.gif

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Syndicated - Outbound

Hi @parry2k,

 

I have a problem similar to this one, I am trying to get the YTD Sales from the selected period (month and year) and the previous period (same period from the previous year). I tried the measure you have in the pbix but it did not work.

 

Could you help me please?

 

The file is this one: https://www.dropbox.com/s/tv4ar04dk6b66n5/Sales%20Power%20BI.pbix?dl=0

 

Thanks in advance.

 

Regards.

avatar user
Anonymous
Not applicable

Syndicated - Outbound

@parry2k this is exactly what I need.

 

I was trying to solve it thinking differently, your solution is great. Thank you!

parry2k
Super User
Super User

Syndicated - Outbound

@Anonymous got it, let me see if we can figure out something. Stay tuned!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

Syndicated - Outbound

@Anonymous can you share a sample pbix file, remove sensitive information before sharing, share thru one drive/google drive.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

avatar user
Anonymous
Not applicable

Syndicated - Outbound

@parry2k, I don't know if I did it correctly, but I share the link with the files:

Link to download

parry2k
Super User
Super User

Syndicated - Outbound

@BA_Pete unfortunately that will not work, it will only if you are looking at the data for the current year, if you select, let's say 2018, now relative year will not work and visual will be blank because the relative year for 2018 will be -2.

 

But yes, if always looking at the current year and the previous year, it will work. Depends, how scalable the solution needs to be.

 

Just my 2 cents.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Syndicated - Outbound

Thanks @parry2k , you're absolutely right. I'll retract my previous answer to avoid confusion.

I should really brush-up on my reading skills! 🙂

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




parry2k
Super User
Super User

Syndicated - Outbound

@Anonymous This is how I think it should work, you should add a date dimension in your model, there are many posts on how to do it.

 

Add two measures:

 

count = DISTINCTCOUNT (Table [Incident]) //it is pretty currently selected year

count PY = CALCULATE ( [count], SAMEPERIODLASTYEAR ( DateTable[Date] ) )

 

Use these two measures in the pie chart and use the year slicer from the date dimension, and you will always get to see the selected year data and the previous year data.

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

avatar user
Anonymous
Not applicable

Syndicated - Outbound

Hi @parry2k, thank you for your answer.

I already have a date dimension in my model and that's what I'm using in this graph.

 

If I do it this way, creating 2 measures (count + count LY) will not work for me. I need the legend for the selected year and the previous year to be returned.

 

In your solution I will have the following result:

vmzandonadi_1-1611594601787.png

 

I'd like something like that, but only showing 2 years in the legend:

vmzandonadi_2-1611594670386.png

 

 

 

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)