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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
djs1984
Frequent Visitor

Returning a Percentage Difference from Two Cards

Good Day,

 

I have a Power BI report that shows two cards; Sales last year, and Sales this year. Let's say these cards are

 

This Year: 376

Last Year: 300

 

The result is just the sum of sales, with a filter on the year.

 

I want to create another card that displays the variance between these two, but that would be calculating on the basis of other calculations, and I'm not sure how to do it.

Maybe it's simple, maybe not. I'm kind of stuck...

 

2 ACCEPTED SOLUTIONS
ajohnso2
Super User
Super User

Hey,

Hopefully you already have your sales for TY and LY as seperate measures in this case youcan just create a new measure to calculate the YoY by simply Sales TY - Sales LY.

 

In very basic form

 

Sales TY =
VAR _CurrentYear = MAX('Calendar'[Year]) ** or _CurrentYear = SELECTEDVALUE('Calendar'[Year]) if your using a slicer**

RETURN
CALCULATE(SUM('Fact'[Sales]), ALL('Calendar'[Year]), 'Calendar'[Year] = _CurrentYear)
Sales LY =
VAR _PreviousYear = MAX('Calendar'[Year]) -1 //Previous Year

RETURN
CALCULATE(SUM('Fact'[Sales]), ALL('Calendar'[Year]), 'Calendar'[Year] = _PreviousYear)
Sales YoY =
[Sales TY] - [Sales LY]

 

 

Sales YoY % =
DIVIDE(([Sales TY] - [Sales LY]), [Sales LY], 0)

View solution in original post

Anonymous
Not applicable

Thanks for the reply from Bibiano_Geraldo,cosm and ajohnso2 , please allow me to provide another insight:

Hi, @djs1984 

The solutions they have proposed are excellent. If you find them helpful, please accept their responses as solutions. This will aid the development of our community and help other members with similar issues find solutions more quickly.

vlinyulumsft_0-1732767091210.png

To facilitate your understanding of their ideas, I have created the following example:

vlinyulumsft_1-1732767091211.png

Last Year = 
CALCULATE(
    SUM('Table'[values]),
    YEAR('Table'[Date]) = YEAR(TODAY())-1
)
This Year = 
CALCULATE(
    SUM('Table'[values]),
    YEAR('Table'[Date]) = YEAR(TODAY())
)

Sales Variance = 
VAR SalesThisYear = [This Year]
VAR SalesLastYear = [Last Year]
VAR Variance1 = SalesThisYear - SalesLastYear
   
RETURN 
IF(
        SalesLastYear <> 0, 
       FORMAT ( DIVIDE(Variance1, SalesLastYear, 0), "0.00%"),
        BLANK()
    )

Here's the final result, which I hope meets your requirements.

vlinyulumsft_2-1732767200123.png

Secondly, regarding whether you need to continue using filters, if your card visuals are based on filters, we recommend replacing them with the measures I used. This approach is more convenient, and you can also add the ALL() and ALLSELECTED() functions to the measures to ensure they are affected by the filters.

Last Year1 = 
CALCULATE(
    SUM('Table'[values]),
   FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(TODAY())-1)
)

vlinyulumsft_3-1732767228446.png

For further details, please refer to:

Power BI DAX: ALL vs. ALLSelected - RADACAD

ALLSELECTED function (DAX) - DAX | Microsoft Learn
ALL function (DAX) - DAX | Microsoft Learn
 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

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

7 REPLIES 7
Bibiano_Geraldo
Super User
Super User

Hi @djs1984 ,

Assuming you already have the following measures:

  • Sales This Year 
  • Sales Last Year 

Create a new measure with this DAX:

Sales Variance = 
VAR SalesThisYear = [Sales This Year]
VAR SalesLastYear = [Sales Last Year]
VAR Variance = SalesThisYear - SalesLastYear
VAR VariancePercentage = 
    IF(
        SalesLastYear <> 0, 
        DIVIDE(Variance, SalesLastYear, 0), 
        BLANK()
    )
RETURN 
VariancePercentage

 

 

Anonymous
Not applicable

Yes.

You can incorporate the filter into the measure.
( As is done in both suggested solutions by me and @ajohnso2  )
 
See the suggested solutions. The filter is included in the measures by using the "CALCULATE"-function:

CALCULATE(expression , filter )

CALCULATE evaluates an expression, filtered on the second argument.

The filter applied to the cards can be removed when they are in the measures.

ajohnso2
Super User
Super User

Its not ideal having the filter on the visuals as this is more than likely a static value (you will need to constantly update the filter manually). You wont be able to show your variance in a card with a visual filter as you will need the filter context of both years.

 

I am not sure of your model structure so I can only say to follow standard guidelines.

- Follow a star schema

- Have a calendar dimension

- Have you Fact data

- Create the relevant relationships

 

If you are able to share your model we can advise the best route

Anonymous
Not applicable

Hi.

You can use this method:

- Create a measures for each of your two cards
- Create a new measure to calculate difference using the two measures.
- Add each of the three measures to a card

Eg.


 

Sales This Year =
    Calculate(
    SUM('Sales'[Amount]),
    YEAR('Dim calender'[Date]) = YEAR (TODAY () )
    
)

 


, and

 

Sales Prev Year =
    Calculate(
    SUM('Sales'[Amount]),
    YEAR('Dim calender'[Date]) = YEAR (TODAY () ) -1
    
)

 


, and the variance as:

 

Difference =
[Sales Prev Year] - [Sales this year]

 


It should work, replace the tables references to relevant tables in your data model.

If this solved your problem, consider mark answer as a slolution so others can find solution fast.

Kind regards
Cosm

ajohnso2
Super User
Super User

Hey,

Hopefully you already have your sales for TY and LY as seperate measures in this case youcan just create a new measure to calculate the YoY by simply Sales TY - Sales LY.

 

In very basic form

 

Sales TY =
VAR _CurrentYear = MAX('Calendar'[Year]) ** or _CurrentYear = SELECTEDVALUE('Calendar'[Year]) if your using a slicer**

RETURN
CALCULATE(SUM('Fact'[Sales]), ALL('Calendar'[Year]), 'Calendar'[Year] = _CurrentYear)
Sales LY =
VAR _PreviousYear = MAX('Calendar'[Year]) -1 //Previous Year

RETURN
CALCULATE(SUM('Fact'[Sales]), ALL('Calendar'[Year]), 'Calendar'[Year] = _PreviousYear)
Sales YoY =
[Sales TY] - [Sales LY]

 

 

Sales YoY % =
DIVIDE(([Sales TY] - [Sales LY]), [Sales LY], 0)

I have one measure - Sales Total, and the date is just a filter applied to each visual, it's not in the measure. Would I need to have the filter in the measure?

Anonymous
Not applicable

Thanks for the reply from Bibiano_Geraldo,cosm and ajohnso2 , please allow me to provide another insight:

Hi, @djs1984 

The solutions they have proposed are excellent. If you find them helpful, please accept their responses as solutions. This will aid the development of our community and help other members with similar issues find solutions more quickly.

vlinyulumsft_0-1732767091210.png

To facilitate your understanding of their ideas, I have created the following example:

vlinyulumsft_1-1732767091211.png

Last Year = 
CALCULATE(
    SUM('Table'[values]),
    YEAR('Table'[Date]) = YEAR(TODAY())-1
)
This Year = 
CALCULATE(
    SUM('Table'[values]),
    YEAR('Table'[Date]) = YEAR(TODAY())
)

Sales Variance = 
VAR SalesThisYear = [This Year]
VAR SalesLastYear = [Last Year]
VAR Variance1 = SalesThisYear - SalesLastYear
   
RETURN 
IF(
        SalesLastYear <> 0, 
       FORMAT ( DIVIDE(Variance1, SalesLastYear, 0), "0.00%"),
        BLANK()
    )

Here's the final result, which I hope meets your requirements.

vlinyulumsft_2-1732767200123.png

Secondly, regarding whether you need to continue using filters, if your card visuals are based on filters, we recommend replacing them with the measures I used. This approach is more convenient, and you can also add the ALL() and ALLSELECTED() functions to the measures to ensure they are affected by the filters.

Last Year1 = 
CALCULATE(
    SUM('Table'[values]),
   FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(TODAY())-1)
)

vlinyulumsft_3-1732767228446.png

For further details, please refer to:

Power BI DAX: ALL vs. ALLSelected - RADACAD

ALLSELECTED function (DAX) - DAX | Microsoft Learn
ALL function (DAX) - DAX | Microsoft Learn
 

Please find the attached pbix relevant to the case.

 
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors