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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Using a Variable in TOTALYTD for "Year End"

I'd like to be able to use a variable in for the requirement in this formula,

TOTALYTD( [Expenses], Calendar[Date], ALL('Calendar'), "9/30")

I want to be able to use a variable to replace the "9/30" so I can easily change this in multiple calculations. When I do input a variable there, even when I try making the variable exactly the same as what's there now, the formula breaks.

 

Has anyone experienced this? 

1 REPLY 1
sturlaws
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

I can't find a way to make totalytd accept the end-of-year string as anyting other than a string.

The workaround would be to create a measure for ytd yourself:

Measure =
VAR _currentDate =
    CALCULATE ( MAX ( Dates[Date] ) )
VAR _eoyMonth =
    MONTH ( [endOfYear] )
VAR _eoyDay =
    DAY ( [endOfYear] )
VAR _min =
    IF (
        MONTH ( _currentDate ) > _eoyMonth;
        DATE ( YEAR ( _currentDate ); _eoyMonth; _eoyDay );
        DATE ( YEAR ( _currentDate ) - 1; _eoyMonth; _eoyDay )
    )
VAR _max =
    IF (
        MONTH ( _currentDate ) > _eoyMonth;
        DATE ( YEAR ( _currentDate ) + 1; _eoyMonth; _eoyDay );
        DATE ( YEAR ( _currentDate ); _eoyMonth; _eoyDay )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[sales] );
        FILTER (
            ALL ( Dates );
            Dates[Date] <= MAX ( Dates[Date] )
                && Dates[Date] > _min
                && Dates[Date] <= _max
        )
    )

 

where 

 

endOfYear = date(2019;6;30)

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.