Reputation: 83
I have a simple profit value that I'd like to calculate as YTD but only show the figures up to the current month.
i.e. With just YTD it looks like this:
But I'd like it to look like this:
I am currently using the following DAX formula to achieve this:
Profit YTD:=IF (
MAX ( 'Date'[Date_Key] ) <= TODAY (),
( TOTALYTD ( [Profit], 'Date'[Date_Key] ) ),
BLANK ()
)
This works great until I use the date hierarchy (Year-Quarter-Month) as then the data for the current year is not displayed:
I know why this happens, but I don't know how to resolve this in DAX. Any help greatly appreciated.
Upvotes: 0
Views: 121
Reputation: 83
I found a solution on sqlbi.com:
hiding-future-dates-for-calculations-in-dax
From this I created the following calculated column in the Date table:
DateWithProfit= 'Date'[Date] <= NOW()
I then added the following measure:
Profit YTD:=
CALCULATE (
[Profit],
CALCULATETABLE ( DATESYTD ( 'Date'[Date] ), 'Date'[DateWithProfit] = TRUE )
)
Works perfectly.
Upvotes: 0