Forum Discussion
TOTALYTD variable year
- 4 years ago
Hi C4L84
Here is the file with the solution https://we.tl/t-LZzcXfkSG3
Your Mesure Code isRunning Total Spend = VAR _EndDate = MAX ( 'FY end'[Date] ) VAR _CurrentYear = SELECTEDVALUE ( 'Calendar'[Financial year] ) VAR _StartDate = DATE ( _CurrentYear, MONTH ( _EndDate ), DAY ( _EndDate ) ) VAR _CurrentDate = MAX ( 'Calendar'[Date] ) VAR _Result = CALCULATE ( SUM ( Sheet1[Spend] ), 'Calendar'[Date] >= _StartDate, 'Calendar'[Date] <= _CurrentDate ) RETURN _Result
Hi tamerj1 - it's easier to understand
- tamerj14 years agoCommunity Champion
Then can you try without the time format?
- C4L844 years agoAdvocate II
I'm sorry, I don't understand... I'm not formatting the time - it's formatted dd/mm day/month eg 22/03
- tamerj14 years agoCommunity Champion
C4L84
Ok. Then I guess you mean to say that the date has text data type and this is the source of the error. Usually you should check and fix data type of all columns in power query before loading the data. However, if this is not what you want to do and if you don't want to create a new column in the 'FY End' table with the correct data type date then you can use the following code. Hopefully, DAX will automatically convert the string numbers into integers:Running Total Spend = VAR _EndDate = MAXX ( ADDCOLUMNS ( 'FY end', "@Date", DATE ( 1, RIGHT ( 'FY end'[Date], 2 ), LEFT ( 'FY end'[Date], 2 ) ) ), [@Date] ) RETURN TOTALYTD ( SUM ( 'Invoiced Sales'[Spend] ), 'Calendar'[Date], _EndDate )If the error remains then use this one
Running Total Spend = VAR _EndDate = MAXX ( ADDCOLUMNS ( 'FY end', "@Date", DATE ( 1, INT ( RIGHT ( 'FY end'[Date], 2 ) ), INT ( LEFT ( 'FY end'[Date], 2 ) ) ) ), [@Date] ) RETURN TOTALYTD ( SUM ( 'Invoiced Sales'[Spend] ), 'Calendar'[Date], _EndDate )