Forum Discussion
DAX - Column content based on slicer selection
- 8 years ago
Hi Anonymous,
Did you had a measure or a calculated column?
I'm assuming that since your data is always the same in the sample you showned that you created a calculated column, this will give you the maximum value of the date column in your data.
Below you can see the same measure as you have but in a calculated colum (COLUMN_REF) and in a measure (MEASURE_REF) the only one that changes accordingly to the slicer is the measure.
You need to change your formula to a measure instead of the column.
Regards,
MFelix
Hi I am just opening the thread again. I am trying to do something similar.
I have created a slicer table with values - YearToDate and Rolling12Months.
My Main data table (which is unrelated to Slicer table) has data for past 24 months. In thsi table, I would like to calculate a column which gives values as - Current Year and Previous Year, based on the date and the slicer selected.
So if I select YearTodate as Slicer my calculated column should have values like
Date Calculated Column
01/01/2020 Current Year
02/01/2020 Current Year
01/01/2019 Previous Year
02/01/2019 Previous Year
03/01/2019 Null
04/01/2019 Null
.
.
.
and so on.
Can you suggest how can I achieve this. I have tried SelectedVlues, but it soes not help.
H Anonymous ,
You cannot make calculated columns based on slicers selection because slicers are used to filter out information from a dataset so you are refering to the data itself again.
What is you main objective with this column is to calculate the Current Year values and the previous years?
This can be achieve by the use of a table of dates and a use of filters in the measures, something similar to:
PY Value = CALCULATE (SUM(Table[Column]); DATEADD(DateTable[Date]; -1 ; YEAR))
This is just an example but if you want to have more intricate calculations based on dates selected or quaters that is also possible.
If you can explain and give some data example I can try and help you to achieve the response you need.