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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
GeraSanz11
Frequent Visitor

Compare data using a given filter

Hi there!

 

Im having some trouble with comparing information. I have a data set like this (It's only annual information no months nor days)

 

Year  | Amount

2015 |  123

2015 |  421

2014 |  321

2014 | 654

2013 | 987

2013 | 876

 

I want to compare the total Amount per year with the last year BUT using Slicers, so if i choose 2015 in the slicer, it will compare automatically with 2014, and if i choose 2014, it will be compared with 2013 and so on

 

any advice? 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

one possible solution could be to create a measure that calculates the amount of previous year like so:

amount PY = 
IF(HASONEFILTER('Table1'[Year]),
 var py = values('Table1'[Year]) -1
 return
 CALCULATE(SUM('Table1'[Amount]),
  'Table1'[Year] = py
 ),
 BLANK()
)

Now you can use both measures in any visualization, if more than one year is selected or NONE, the measure returns a BLANK() / NULL value  

 

Hope this is what you are looking for



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey,

 

one possible solution could be to create a measure that calculates the amount of previous year like so:

amount PY = 
IF(HASONEFILTER('Table1'[Year]),
 var py = values('Table1'[Year]) -1
 return
 CALCULATE(SUM('Table1'[Amount]),
  'Table1'[Year] = py
 ),
 BLANK()
)

Now you can use both measures in any visualization, if more than one year is selected or NONE, the measure returns a BLANK() / NULL value  

 

Hope this is what you are looking for



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thank you so much!

 

Just what i needed, i don't understand very well the whole formula (the py for example) but for sure is what i was looking for... ill look for more documentation!

 

THX

Hey,

 

what happens is this

  1. Check if just one year is selected in the slicer
    1. if just one year is selected
      1. define a variable py it's just a name for previous year
      2. use values() to return a table with just one column, the special part about values() is this, if the table contains just one row it can be used as a skalar value and it's possible to subtract 1
      3. use the variable to filter the table where the year column equals the variable 
    2. if more than year or none year is selected return blank()


Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors