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
jasemilly
Helper III
Helper III

using variables in function TotalYTD

Hi I am trying to create a measure to show % increase/decrease between the current rolling year, sum of values one whole year ending today, against the previous.

I have been trying to use TOTALYTD, I don't see to be able to pass a variable into the function

var EndDay  = "06/10" /*day(today()) & "/" & month(today()) */

var CurYear = TOTALYTD([Vehicles],Dates[Date], EndDay )
 
It gives an error  TRUE?FALSE expression does not specify a column???
 
If I hardcode "06/10" in the function it all works fine 

 
 
At the moment I am using the function  DatesInPeriodbut this seems to have an issue with the leap year  the value is a little out but fine when is say -366

CALCULATE (
[Vehicles],
DATESINPERIOD ( 'dates'[Date], TODAY(), -365, DAY )
)
 
thanks for all help


1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

@jasemilly  How about using YEAR instead of DAY in DATESINPERIOD function? Just like below. This will work well without the leap year issue.

CALCULATE (
[Vehicles],
DATESINPERIOD ( 'dates'[Date], TODAY(), -1, YEAR )
)

 

Reference: https://docs.microsoft.com/en-us/dax/datesinperiod-function-dax

 

Best Regards,

Community Support Team _ Jing Zhang

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

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

@jasemilly  How about using YEAR instead of DAY in DATESINPERIOD function? Just like below. This will work well without the leap year issue.

CALCULATE (
[Vehicles],
DATESINPERIOD ( 'dates'[Date], TODAY(), -1, YEAR )
)

 

Reference: https://docs.microsoft.com/en-us/dax/datesinperiod-function-dax

 

Best Regards,

Community Support Team _ Jing Zhang

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

Anonymous
Not applicable

Well, you can't pass a variable to this function. It has to be a true constant. (Funnily enough, variables in DAX are contant once defined 🙂

 

Please read this: https://dax.guide/totalytd/

 

Marco Russo does not recommend using the TOTALYTD function. There's a whole article about this. Please use DATESYTD instead with a suitable expression under CALCULATE.

amitchandak
Super User
Super User

@jasemilly , Try like

CALCULATE (
[Vehicles],DATESBETWEEN('dates'[Date], date(year(today())-1,month(today()),day(today())), TODAY())
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.