Forum Discussion

alsm's avatar
alsm
Icon for Helper III rankHelper III
3 years ago
Solved

calculate sum with multiple criteria

Hello

I have a table that somewhat looks like

IndustrySub-IndustryVolume
Energy Equipment & ServicesDrilling100
Energy Equipment & ServicesOil & Gas Equipment & Services150
Oil, Gas & Consumable FuelsDrilling50
Oil, Gas & Consumable FuelsIntegrated Oil & Gas75
Oil, Gas & Consumable FuelsOil & Gas Exploration & Production200
Metals & MiningDrilling225
Metals & MiningDiversified Metals & Mining90
Metals & MiningCopper75

 

I want to calculate sum with following filter criteria

Industry IN {Energy Equipment & Services, Oil, Gas & Consumable Fuels} and Sub-Industry = Drilling

OR

Industry IN {Metals & Mining} and Sub-Industry = 'Diversified Metals & Mining'

 

How to write this combination of AND and OR conditions in Calculate(Sum(Volume),..???..)

 

  • Hi alsm ,

    There are many ways to write this, however this works:

    Sum =
    CALCULATE (
        SUM ( IndustryResearch[Volume] ),
        FILTER (
            IndustryResearch,
            IndustryResearch[Industry]
                IN { "Energy Equipment & Services", "Oil, Gas & Consumable Fuels" }
                && IndustryResearch[Sub-Industry] = "Drilling"
        )
    )
        + CALCULATE (
            SUM ( IndustryResearch[Volume] ),
            FILTER (
                IndustryResearch,
                IndustryResearch[Industry] = "Metals & Mining"
                    && IndustryResearch[Sub-Industry] = "Diversified Metals & Mining"
            )
        )
    





    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel

3 Replies

  • alsm's avatar
    alsm
    Icon for Helper III rankHelper III

    Nathaniel_C Thank you for your reply, it works. I have a followup question (don't know if I should ask another question or simply here). Can I create a filter variable which has common filter criteria and then use this common filter + additional filter lines in each calculate rows?

    • Nathaniel_C's avatar
      Nathaniel_C
      Icon for Community Champion rankCommunity Champion

      Hi alsm ,

       

      Would you give me an example of what you mean?

       


      Let me know if you have any questions.

      If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
      Nathaniel

  • Nathaniel_C's avatar
    Nathaniel_C
    Icon for Community Champion rankCommunity Champion

    Hi alsm ,

    There are many ways to write this, however this works:

    Sum =
    CALCULATE (
        SUM ( IndustryResearch[Volume] ),
        FILTER (
            IndustryResearch,
            IndustryResearch[Industry]
                IN { "Energy Equipment & Services", "Oil, Gas & Consumable Fuels" }
                && IndustryResearch[Sub-Industry] = "Drilling"
        )
    )
        + CALCULATE (
            SUM ( IndustryResearch[Volume] ),
            FILTER (
                IndustryResearch,
                IndustryResearch[Industry] = "Metals & Mining"
                    && IndustryResearch[Sub-Industry] = "Diversified Metals & Mining"
            )
        )
    





    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel