Forum Discussion

vedantsri's avatar
vedantsri
Helper I
3 years ago
Solved

How to fix circular dependency in two calculated columns using switch statement?

Hi All!   Firstly thank you to anyone helping out!   So I have this office table: Office Tier A Elite B Mid C Mid D Low   Now I wanted to get Demand and Supply numbers f...
  • ichavarria's avatar
    3 years ago

    Hi vedantsri,

     

    The reason why you're seeing a circular dependency error is that the DemandColumn and SupplyColumn calculated columns are referencing each other. To resolve this issue, you can create two separate measures for Demand and Supply instead of calculated columns.

     

    Here's how you can do it:

     

    1. Create the following measures:

       

       

      EliteDemand = CALCULATE(SUM('DemandTable'[Value]), 'Office'[Tier] = "Elite")

      MidDemand = CALCULATE(SUM('DemandTable'[Value]), 'Office'[Tier] = "Mid")


      LowDemand = CALCULATE(SUM('DemandTable'[Value]), 'Office'[Tier] = "Low")


      EliteSupply = CALCULATE(SUM('SupplyTable'[Value]), 'Office'[Tier] = "Elite")


      MidSupply = CALCULATE(SUM('SupplyTable'[Value]), 'Office'[Tier] = "Mid")


      LowSupply = CALCULATE(SUM('SupplyTable'[Value]), 'Office'[Tier] = "Low")

       

       

    2. Create two new measures for the Demand and Supply card visuals using the following formulas:


      DemandColumn = SWITCH(SELECTEDVALUE('Office'[Tier]), "Elite", [EliteDemand], "Mid", [MidDemand], "Low", [LowDemand])

      SupplyColumn = SWITCH(SELECTEDVALUE('Office'[Tier]), "Elite", [EliteSupply], "Mid", [MidSupply], "Low", [LowSupply])

    3. Add the 'Office' table to your report and create a slicer for the 'Office' column. This slicer will be used to select an office and update the Demand and Supply card visuals accordingly.

     

    With these measures and formulas, you should be able to achieve your goal of having two card visuals, one for Demand and one for Supply, that display the values based on the selected office and tier.

     

    Best regards, 

    Isaac Chavarria

    If this post helps, then please consider Accepting it as the solution and give Kudos to help the other members find it more quickly