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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
RilwanFlame
Helper III
Helper III

YTD % DAX calculation.

Hi  - I hope someone can help me. I am lookign to calculate YTD%, (which is basically supposed to be -- (CurrentQ - prior 12/31) / prior 12/31) ). 

I have used quick measure to calculate QoQ %, which give me the result I want but when I tried using same format to calculate YTD % i was getting an error. 

RilwanFlame_0-1648496932506.png

RilwanFlame_2-1648497089805.png

 

 

1 ACCEPTED SOLUTION

My mistake, previous calculations will not work in your model.
try this:

YoY% for YTD = 

IF(
    ISFILTERED('Data2'[Date]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __PREV_YEAR = CALCULATE(TOTALYTD(SUM('Data2'[$]), 'Data2'[Date].[Date]), DATEADD('Data2'[Date].[Date], -1, YEAR))
    RETURN
    DIVIDE(TOTALYTD(SUM('Data2'[$]), 'Data2'[Date].[Date]) - __PREV_YEAR, __PREV_YEAR)
)


This will compare the current YTD accumulation to previous year YTD and calculate the YOY growth. 

View solution in original post

17 REPLIES 17
Tutu_in_YYC
Super User
Super User

Hi Rilwan, 
try this:

 

YTD% =
VAR _Current = TOTALYTD(SUM(Data2[$]), Data2[Date])
VAR _Previous = CALCULATE( TOTALYTD(SUM(Data2[$]), Data2[Date]), SAMEPERIODLASTYEAR(Data2[Date]))
RETURN
DIVIDE( _Current - _Previous, _Previous, 0)

Thank you so much for the quick reply. I did try but only getting 0 values.

RilwanFlame_0-1648498473731.png

 

Do you have a year slicer in the report? If yes, can you choose a year?

Yes, i did choose a year and still getting 0 values. 

 

Can you create this for validation, and put it in the matrix? Upload a snapshot.

Validation =
VAR _Current = TOTALYTD(SUM(Data2[$]), Data2[Date])
VAR _Previous = CALCULATE( TOTALYTD(SUM(Data2[$]), Data2[Date]), SAMEPERIODLASTYEAR(Data2[Date]))
RETURN
_Current & "---" & _Previous

 

RilwanFlame_0-1648502340876.png

 

That tells me that you do not have data for previous year. Is that the case?

RilwanFlame_1-1648503359865.png

 

What year are you looking at in the below snapshot?

Tutu_in_YYC_0-1648503855944.png

 

I do have data for previous year. Also, understand these are quarterly data. Let me get you a screen shot. 

My mistake, previous calculations will not work in your model.
try this:

YoY% for YTD = 

IF(
    ISFILTERED('Data2'[Date]),
    ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
    VAR __PREV_YEAR = CALCULATE(TOTALYTD(SUM('Data2'[$]), 'Data2'[Date].[Date]), DATEADD('Data2'[Date].[Date], -1, YEAR))
    RETURN
    DIVIDE(TOTALYTD(SUM('Data2'[$]), 'Data2'[Date].[Date]) - __PREV_YEAR, __PREV_YEAR)
)


This will compare the current YTD accumulation to previous year YTD and calculate the YOY growth. 

Thank you so much. I apprciate you. That worked right. 

 

glad to hear!

Hi - What about in the case of wanting to calculate,

example
YTD = Q4 2021 - Q4 2020
QTD = Q4 - Q3

YTD = Q4 2021 - Q4 2020 : As in the difference of the amount beween current year and previous year?

QTD = Q4 - Q3 : Difference from current Quarter  to the previous Quarter ( i.e Qn - Qn-1)?

Got this sorted. Thank you 

 

But i have another question on how to write this R code in Dax. 

 

Filter(!is.na(SentMonth), Surveytaken==2)

Ooh not proficient in R.

But try this
EOC_Sent = CALCULATE(countrows('Sheet1'), 'Sheet1'[SurveyTaken]=2)

 

If it doesnt work, it means your table structure may not be correct.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.