Forum Discussion
DAX Add months to SELECTEDVALUE Date
- Anonymous5 years ago
It seems that I found the solution, but I don't understand why it works at all.
I now use the following measure:
L3.2 = VAR _SelDate = FORMAT(DATEADD('DIM Kalender'[Datum],2,MONTH), "YYYYMM") RETURN CALCULATE( COUNT('FACT ACM'[EAN]), 'FACT ACM'[Subonderwerp] = "L3.2", FORMAT('FACT ACM'[InvoiceDate],"YYYYMM") = _SelDate )When I make a selection in the slicer above and select August, it returns the values of October. However, this Calendar table HAS NO RELATIONSHIP with the table 'FACT ACM'. What is the reason why this works without SELECTEDVALUE?
Kind regards,
Igor
- 5 years ago
Sorry I just realized, When you perform a SELECTEDVALUE() on a column you are no longer working with a column but instead with a single value. Dateadd() requires a columnstatement to work so the combination of selectedvalue() and dateadd() will never work!
You can work around this by simply adding months manually, along the lines if this:
VAR NewMonth = IF( MONTH( Calendar[Date] ) = 11 , 1 , IF( MONTH( Calendar[Date] ) = 12 , 2 , MONTH( Calendar[Date]) +2 ))
VAR NewYear = IF( MONTH( Calendar[Date] ) > 10 , YEAR( Calendar[Date] ) +1 , YEAR( Calendar[Date] ))
This would mean that you can completly skip the dateadd, meaning that you can use selectedvalue()
But if I understood you correctly you already got it to work! 🙂
/J
Thanks a lot, this is a very helpful explanation indeed.
I got it to work, but using your solution also does the trick.
Kind regards,
Igor
Great to hear, good luck with future calculations!
Br,
J