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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors