Forum Discussion

forgetmenot's avatar
forgetmenot
Helper I
2 years ago
Solved

Switch Formula with multiples condition based off existing measures and a column i have created.

I am a newbie and am really struggling with getting the logic right to create a Switch Formula.  I have been asked to provide the following:  If Variance is within Qtr1 FY (April to Jun) then t...
  • Alef_Ricardo_'s avatar
    2 years ago

    To implement the logic you described with a switch formula based on financial quarters and tolerance levels, you can use the `SWITCH` function along with additional `IF` statements to check the financial quarter and apply the appropriate tolerance criteria. Here's a DAX formula that accomplishes this:

    ```DAX
    Result =
    VAR CurrentQuarter = SELECTEDVALUE(Calendar[FYQ])
    VAR Variance = [MONTH_%_DIFF]
    VAR ToleranceLevel =
    SWITCH(
    TRUE(),
    CurrentQuarter = "Q1 FY" && (Variance > 0.1 || Variance < -0.1), 500000,
    CurrentQuarter = "Q2 FY" && (Variance > 0.1 || Variance < -0.1), 500000,
    TRUE(), 100000
    )
    VAR WithinTolerance =
    IF(
    ABS(Variance) <= ToleranceLevel,
    "In Tolerance",
    "Outside Tolerance"
    )
    RETURN
    WithinTolerance
    ```

    Here's how this formula works:

    1. `CurrentQuarter` calculates the financial quarter based on your calendar table.

    2. `Variance` represents the percentage difference that you have.

    3. `ToleranceLevel` calculates the tolerance level based on the financial quarter and whether the variance exceeds 10%. If it's Q1 or Q2 and the variance exceeds 10%, the tolerance is 500,000. Otherwise, it's 100,000.

    4. `WithinTolerance` checks whether the absolute value of the variance is within the calculated tolerance level and returns "In Tolerance" or "Outside Tolerance" accordingly.

    5. The `Result` measure returns the result of the `WithinTolerance` calculation.

    This formula considers the financial quarter, percentage variance, and appropriate tolerance level, and then returns "In Tolerance" or "Outside Tolerance" based on these conditions. Adjust the tolerance levels and conditions as needed to match your specific requirements.