Hi,
i've developed this calculation to use in a model where 'dim posting date' as an hierarchy year|month|date. It allows me to:
1) if a month is selected and no date is selected, it does the calculation for Month
2) if a month is selected AND dates are selected, it does the calculation for the day. (already changed to allow non contiguous dates)
3) Finally, other situation is only the year selected, and in this case i want to appear BLANK.
But now i have a problem, in 2), at 29, 30 and 31 of March i get the (last) value of 28 February. I don't want that, How can i change the calculation to make it exactly return the value for one month before. If the day doesn't exist, i want blank to appear.
(the "opposite" happens without problems: at 28 February i get the value of 28 January)
Sales Amount M-1 :=
IF (
HASONEVALUE ( 'Dim Posting Date'[Month] )
&& NOT ISFILTERED ( 'Dim Posting Date'[Date] );
CALCULATE (
[Sales Amount];
DATESMTD ( DATEADD ( 'Dim Posting Date'[Date]; -1; MONTH ) )
);
IF (
HASONEVALUE ( 'Dim Posting Date'[Month] )
&& ISFILTERED ( 'Dim Posting Date'[Date] );
SUMX (
VALUES ( 'Dim Posting Date'[Date] );
CALCULATE (
[Sales Amount];
DATEADD ( 'Dim Posting Date'[Date]; -1; MONTH )
)
);
BLANK ()
)
)
i've developed this calculation to use in a model where 'dim posting date' as an hierarchy year|month|date. It allows me to:
1) if a month is selected and no date is selected, it does the calculation for Month
2) if a month is selected AND dates are selected, it does the calculation for the day. (already changed to allow non contiguous dates)
3) Finally, other situation is only the year selected, and in this case i want to appear BLANK.
But now i have a problem, in 2), at 29, 30 and 31 of March i get the (last) value of 28 February. I don't want that, How can i change the calculation to make it exactly return the value for one month before. If the day doesn't exist, i want blank to appear.
(the "opposite" happens without problems: at 28 February i get the value of 28 January)
Sales Amount M-1 :=
IF (
HASONEVALUE ( 'Dim Posting Date'[Month] )
&& NOT ISFILTERED ( 'Dim Posting Date'[Date] );
CALCULATE (
[Sales Amount];
DATESMTD ( DATEADD ( 'Dim Posting Date'[Date]; -1; MONTH ) )
);
IF (
HASONEVALUE ( 'Dim Posting Date'[Month] )
&& ISFILTERED ( 'Dim Posting Date'[Date] );
SUMX (
VALUES ( 'Dim Posting Date'[Date] );
CALCULATE (
[Sales Amount];
DATEADD ( 'Dim Posting Date'[Date]; -1; MONTH )
)
);
BLANK ()
)
)
Last edited: