Forum Discussion
selectedvalue dax question
- 1 year ago
Hi there,
You need to understand that SELECTEDVALUE () DAX function returns a scalar value while DATEADD () Returns a table. Also, pay attention to the filter context over here.
Lets understand it a bit futher!
Why It Returns Blank?
The DATEADD function, along with other time intelligence functions, expects a column with dates as input, not a scalar value like what you get from SELECTEDVALUE. When you pass -‘Numbers of Months’[Numbers of Months Value] directly to DATEADD, it's possible that the context is not correctly understood, resulting in an invalid operation and hence returning blank.
What can you do as follows?
Modify the Measure
Open X Months Prior =
VAR SelectedMonths = SELECTEDVALUE('Numbers of Months'[Numbers of Months]) // Get the selected number of months
VAR PriorDate =
CALCULATETABLE(
DATEADD('O 29 Years Monthly'[Date], -SelectedMonths, MONTH),
ALL('O 29 Years Monthly')
)
RETURN
CALCULATE(
SUM('O 29 Years Monthly'[Open]),
FILTER(
ALL('O 29 Years Monthly'),
'O 29 Years Monthly'[Date] IN PriorDate
)
)
I hope this will work for you!!
Hi there,
You need to understand that SELECTEDVALUE () DAX function returns a scalar value while DATEADD () Returns a table. Also, pay attention to the filter context over here.
Lets understand it a bit futher!
Why It Returns Blank?
The DATEADD function, along with other time intelligence functions, expects a column with dates as input, not a scalar value like what you get from SELECTEDVALUE. When you pass -‘Numbers of Months’[Numbers of Months Value] directly to DATEADD, it's possible that the context is not correctly understood, resulting in an invalid operation and hence returning blank.
What can you do as follows?
Modify the Measure
Open X Months Prior =
VAR SelectedMonths = SELECTEDVALUE('Numbers of Months'[Numbers of Months]) // Get the selected number of months
VAR PriorDate =
CALCULATETABLE(
DATEADD('O 29 Years Monthly'[Date], -SelectedMonths, MONTH),
ALL('O 29 Years Monthly')
)
RETURN
CALCULATE(
SUM('O 29 Years Monthly'[Open]),
FILTER(
ALL('O 29 Years Monthly'),
'O 29 Years Monthly'[Date] IN PriorDate
)
)
I hope this will work for you!!