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
AxelKAp
Helper I
Helper I

Calculate YTD and YTD-1 for the same period

Hello,

I would like to calculate the YTD Spend and the YTD -1 Spend for the same period.
For example for 2021 we are in October so I would like to calculate the Spend for 2020 only until October.

For the moment I have created this formula :

Spend YTD-1 = CALCULATE(SUM('Spend consolidé'[Invoice_Accounting_EUR]),SAMEPERIODLASTYEAR('Calendar'[Date]))

But it's not working, when I filter on 2021, with this formula I have the spend for the entire year of 2020 instead of having until October.

Any advice to help me solve my problem ?

Thanks,

Axel

5 REPLIES 5
i26923
New Member

Finally this worked for me!

Spend YTD = CALCULATE(SUM('TableName'[FieldName]), DATESYTD('DateTableName'[Date]))

Spend YTD-1 = CALCULATE([Spend YTD], SAMEPERIODLASTYEAR(DATESYTD('DateTableName'[Date])))

 

I think the clue was filtering by DATESYTD.

CNENFRNL
Community Champion
Community Champion

Spend LYTD =
CALCULATE(
    SUM( 'Spend consolidé'[Invoice_Accounting_EUR] ),
    DATEADD( DATESYTD( 'Calendar'[Date] ), -1, YEAR )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi, I try your formula but it's not working, this formula returns me the whole previous year

smpa01
Super User
Super User

@AxelKAp  can you try this for YTD calculation

 

 

YTDSumCY=
CALCULATE (
    SUM ( 'Spend consolidé'[Invoice_Accounting_EUR] ),
    'Calendar'[Calendar_Date] <= MAX ( 'Spend consolidé'[Date] ),
    ALL ( 'Calendar'[Calendar_Date] )
)

YTDSumPY = CALCULATE ([YTDSumCY], SAMEPERIODLASTYEAR('Calendar'[Calendar_Date]))

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi, I have an error with ths formula, Power BI say me that I can't use MAX() with a TRUE/FALSE condition

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.