Forum Discussion

rachelb123's avatar
rachelb123
Helper I
11 months ago
Solved

Using different calculations based on Column Value with switch/if loop

I am trying to find usage rate = number of days used in quarter/total days in quarter for 5 tools. Some have a different specification for this calculation as stated below: Tool A,B,C = number of da...
  • grazitti_sapna's avatar
    grazitti_sapna
    11 months ago

    Hi rachelb123,

    Thank you for clarification.

    you can follow below approach.

    create tool dimenssion table 

    ToolList =
    DATATABLE(
    "ToolName", STRING,
    {
    {"A"},
    {"B"},
    {"C"},
    {"D"},
    {"E"}
    }
    )

    Create Relationship

    • Relate ToolList[ToolName]UsageRateTable[ToolName].

    • Use ToolList[ToolName] in your matrix (instead of from UsageRateTable).

    Now write below measure 

    TotalWorkingDays = 63 // or dynamic from a calendar table later

    Usage Rate (%) =
    VAR _tool = SELECTEDVALUE('ToolList'[ToolName])
    VAR _usageDays =
    CALCULATE(
    DISTINCTCOUNT('UsageRateTable'[UseDate]),
    KEEPFILTERS(VALUES('ToolList'[ToolName]))
    )
    RETURN
    SWITCH(
    TRUE(),
    _tool IN {"D","E"}, IF(_usageDays > 0, 1, 0),
    DIVIDE(_usageDays, [TotalWorkingDays], 0)
    ) * 100