The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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?
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.
User | Count |
---|---|
15 | |
8 | |
6 | |
6 | |
5 |
User | Count |
---|---|
25 | |
13 | |
13 | |
8 | |
8 |