Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

SWITCH() Not Working Properly In Dynamic Measure

I have a working measure defined as such (note that [Forecast Volume] external measure is returning a result properly within the CALCULATE() filter context):     Current Period = /* Define the c...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Thanks ... If you are referring to my last post, that was me just trying what was suggested by lbendlin 

    In the OP, I am specifying a VAR (Target) with SWITCH() containing VALUES(<column>), which should return a single colum like SQL "SELECT DISTINCT". If a row contains the result (e.g., "Revenue ($)"), then return the table [Forecast $] (which is a measure).

    Then:

     

    RETURN
        IF(
            SELECTEDVALUE('Date'[Fiscal Year]) = YEAR(FYStartDate) + 1,
            CALCULATE(
                Target,
                commonPeriod
            ),
            Target
        )

     

    When I specify the actual table-measure in place of "Target", this measure returns the correct result, which is the filtered result of CALCULATE([Forecast $],commonPeriod) or just [Forecast $] as in the IF(). The problem is that the result of SWITCH() ... e.g., [Forecast $] is not treated the same as just directly substituting [Forecast $] in CALCULATE().

    It should work, but the DAX Formatter is obviously parsing this syntax to produce an incorrect result that must not actually resolve to [Forecast $].

    Ultimately, I am trying to dynamically swap out measures into a single measure according to a slicer selection rather than creating four measures that each pass a single measure with the SWITCH() existing inside a separate measure calling each of the four.

    I was able to achieve the desired result by just replicating the measure in the OP 4x for each specific measure, but that seems redundant.