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
olimilo
Continued Contributor
Continued Contributor

YOY Measure returning incorrect value in matrix with Client as context

I'm trying to get the YOY of two metrics based on the date and the client. When I plot them in a table with only the Year as the context, I get the correct value:

 

olimilo_1-1756878372289.png

However, when I plot this on a matrix with the Client as the context, the YOY values return incorrect values:

 

olimilo_0-1756878332674.png


This is how I am computing for the YOY AU. YOY MD is the SUM of the MD column instead of COUNTROWS. Am I missing a row context here that's why the measure is returning an incorrect value?

YOY AU = 
    VAR _year = MAX('AWF'[Year])
    VAR _currval = COUNTROWS('AWF')
    VAR _prevval = 
        CALCULATE(
            COUNTROWS('AUWF'),
            'AWF'[Year] = _year - 1
        )
    RETURN
    CALCULATE(DIVIDE(_currval - _prevval, _prevval))

 

1 ACCEPTED SOLUTION

Hello @olimilo,
Thank you for reaching out to the Microsoft fabric community forum. 

I tested your scenario in Power BI Desktop with sample data, and I was able to reproduce the issue you described where the YOY measure returned incorrect values when Client was added to the matrix.

The root cause is that the original measure was not correctly maintaining the Client context when retrieving the prior-year values. After adjusting the DAX, the YOY values now calculate as expected both at the Year level and the Year + Client level.

Here are the corrected measures:

Total AU = SUM(AWF[AU])

Total MD = SUM(AWF[MD])



YOY AU =

VAR _year = MAX(AWF[Year])

VAR _currval = [Total AU]

VAR _prevval =

   CALCULATE (

       [Total AU],

       FILTER (

           ALL (AWF),

           AWF[Year] = _year - 1

               && AWF[Client] = MAX(AWF[Client])

       )

   )

RETURN

DIVIDE (_currval - _prevval, _prevval)



YOY MD =

VAR _year = MAX(AWF[Year])

VAR _currval = [Total MD]

VAR _prevval =

   CALCULATE (

       [Total MD],

       FILTER (

           ALL (AWF),

           AWF[Year] = _year - 1

               && AWF[Client] = MAX(AWF[Client])

       )

   )

RETURN

DIVIDE (_currval - _prevval, _prevval)

With these measures, the matrix now returns the correct YOY values per Client and per Year.

For example, with the sample dataset:

vhjannapu_0-1756983650671.jpeg

For your reference, I am attaching the .pbix file that demonstrates the corrected implementation.

Best regards,
Harshitha jannapu.

View solution in original post

7 REPLIES 7
danextian
Super User
Super User

'AWF'[Year]

This only sees the current row and not the whole table. Try

FILTER ( ALL ( 'AWF'[Year] ), 'AWF'[Year] = _year -1 )

USE 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
olimilo
Continued Contributor
Continued Contributor

It's still not quite returning the correct value:

 

olimilo_0-1756879492115.png

Like for row 1, I am expecting -40.74% and -40.87%.

 

~YOY AU = 
    VAR _year = MAX('AWF'[Year])
    VAR _currval = COUNTROWS('AWF')
    VAR _prevval = 
        CALCULATE(
            COUNTROWS('AWF'),
            FILTER(ALL('AWF'[Year]), 'AWF'[Year] = _year - 1)
        )
    RETURN
    DIVIDE(_currval - _prevval, _prevval)

 

Hello @olimilo,
Thank you for reaching out to the Microsoft fabric community forum. 

I tested your scenario in Power BI Desktop with sample data, and I was able to reproduce the issue you described where the YOY measure returned incorrect values when Client was added to the matrix.

The root cause is that the original measure was not correctly maintaining the Client context when retrieving the prior-year values. After adjusting the DAX, the YOY values now calculate as expected both at the Year level and the Year + Client level.

Here are the corrected measures:

Total AU = SUM(AWF[AU])

Total MD = SUM(AWF[MD])



YOY AU =

VAR _year = MAX(AWF[Year])

VAR _currval = [Total AU]

VAR _prevval =

   CALCULATE (

       [Total AU],

       FILTER (

           ALL (AWF),

           AWF[Year] = _year - 1

               && AWF[Client] = MAX(AWF[Client])

       )

   )

RETURN

DIVIDE (_currval - _prevval, _prevval)



YOY MD =

VAR _year = MAX(AWF[Year])

VAR _currval = [Total MD]

VAR _prevval =

   CALCULATE (

       [Total MD],

       FILTER (

           ALL (AWF),

           AWF[Year] = _year - 1

               && AWF[Client] = MAX(AWF[Client])

       )

   )

RETURN

DIVIDE (_currval - _prevval, _prevval)

With these measures, the matrix now returns the correct YOY values per Client and per Year.

For example, with the sample dataset:

vhjannapu_0-1756983650671.jpeg

For your reference, I am attaching the .pbix file that demonstrates the corrected implementation.

Best regards,
Harshitha jannapu.

Hi @olimilo.,
I hope the information provided above assists you in resolving the issue. If you have any additional questions or concerns, please do not hesitate to contact us. We are here to support you and will be happy to help with any further assistance you may need.

Regards,
Harshitha.

Hi @olimilo,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.


Regards,
Harshitha.

Hi @olimilo,

I wanted to follow up and see if you have had a chance to review the information that was shared. If you have any additional questions or need further clarification, please don’t hesitate to reach out. I am here to assist with any concerns you might have.

Regards,
Community Support Team.

Shahid12523
Community Champion
Community Champion

Your YOY AU measure breaks when you add Client to the matrix because _prevval doesn’t inherit the Client filter. To fix it, update your measure like this

 

 

YOY AU =
VAR _year = MAX('AWF'[Year])
VAR _currval = COUNTROWS('AWF')
VAR _prevval =
CALCULATE(
COUNTROWS('AWF'),
'AWF'[Year] = _year - 1,
ALL('AWF'[Year]) -- Removes year filter, keeps Client
)
RETURN
DIVIDE(_currval - _prevval, _prevval)

Shahed Shaikh

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