Forum Discussion

mmvohra's avatar
mmvohra
Helper II
6 months ago
Solved

Make Parameter effective using calculated column

I have a following measure of KPI which is counting the ids using filter in one of the calculated column . Calcualted column contains "Same Work" or not " Not Same work". This calculated column is ba...
  • bariscihan's avatar
    6 months ago

    Hi,

    You’re right — this cannot work with a calculated column because calculated columns are evaluated at data refresh time, not dynamically based on slicer/parameter changes.

    The solution is to move the entire logic into a measure and replace the fixed value 2000 with a What-If parameter (or numeric parameter table).

    Step 1 – Create a What-If Parameter

    Create a parameter (for example: Distance Threshold) and use its selected value:

    Selected Threshold = SELECTEDVALUE('Distance Threshold'[Distance Threshold Value], 2000)

    Step 2 – Replace the Calculated Column Logic with a Measure

    Instead of using [Status], embed the logic directly inside the measure and use the selected threshold:

    Count ID =
    VAR Threshold = [Selected Threshold]
    
    RETURN
    CALCULATE(
        DISTINCTCOUNT(Work[ID]),
        FILTER(
            Work,
            VAR CurrentConsolidatedID = Work[Consolidated ID]
            VAR Previous_Date =
                CALCULATE(
                    MIN(Work[Date]),
                    ALLEXCEPT(Work, Work[Consolidated ID])
                )
            VAR Initial_Distance =
                CALCULATE(
                    MIN(Work[Distance_1]),
                    ALLEXCEPT(Work, Work[Consolidated ID]),
                    Work[Date] = Previous_Date
                )
            VAR DIF = ABS(Work[Distance_1] - Initial_Distance)
            VAR Count_1 =
                CALCULATE(
                    COUNTROWS(Work),
                    ALLEXCEPT(Work, Work[Consolidated ID])
                )
            RETURN DIF <= Threshold && Count_1 > 1
        )
    )

    Now when the parameter changes, the measure recalculates dynamically.

    In short:
    Calculated column → static
    Measure + Parameter → dynamic

    That’s the correct approach here.

    Hope this helps.