Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculated column based on slicer value

I have been searching for hours, but can't find the solution.   I wish to create a calculated column, based on a selected date in a slicer. Most solutions use a MIN or MAX function (in my case so ...
  • v-yalanwu-msft's avatar
    4 years ago

    Hi, Anonymous ;

    Slicers cannot be used in calculated columns.  They can, however, be used in measures.

    Slicers are Filters, and thus use filter context.  Filters can change dynamically based on what is selected, and how filter interactions are defined.  Since measures are dynamic fields calculated on demand, they can leverage this filter context to shape results.

    Then we get to calculated columns.  Calculated columns use row context.  They are populated once at data refresh, and don't update again.  If you change interactions, change slicers, the underlying row context and any calculations performed at load would be unaffected.

     

    So, you should use a measure instead of the calculated column if you would like to change the calculation in a table when the slicer value changed. as follows:

    1.create another Date table.

    Date = VALUES('Periode'[Date])

    2.create a measure.

    Date_selected = 
    CALCULATE(MAX('Date'[Date]),ALLSELECTED('Date'))
    #mnd = DATEDIFF(MAX([Startdatum]),[Date_selected],MONTH)

    The final output is shown below:


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.