Forum Discussion

Eesa's avatar
Eesa
Frequent Visitor
4 years ago
Solved

CALCULATE with multiple filters

Hi all, 

 

I want to create a simple DAX measure that calculates the sum of sales for the column product, selecting only "iphone", "Samsung" and "Hawaii". 

 

I tried with below measure but it does not work. 

 

Smart Phones Sales = CALCULATE(SUM(Sales[Price]), Sales[product] = "iPhone", Sales[product] = "Samsung", Sales[product] = "Hawaii")

 

Thank you for your help 

  • Eesa ,Try this

    Smart Phones Sales =
    CALCULATE (
        SUM ( Sales[Price] ),
        FILTER (
            Sales,
            Sales[product] in { "iPhone","Samsung","Hawaii"}
    ))

4 Replies

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

    Hi Eesa ,

     

    You can try below code:-

    Smart Phones Sales =
    CALCULATE (
        SUM ( Sales[Price] ),
        FILTER (
            Sales,
            Sales[product] = "iPhone"
                && Sales[product] = "Samsung"
                && Sales[product] = "Hawaii"
        )
    )

    iphone,samsung,hawaii is case sensitive so it should be written in same way as its available in dataset.

     

    Thanks,

    Samarth

    • Eesa's avatar
      Eesa
      Frequent Visitor

      Hi Samarth, 

       

      Thank you for your reply. I tried but it does not work. 
      when I tried with single filter like: 

       

      Smart Phones Sales =
      CALCULATE (
          SUM ( Sales[Price] ),
          FILTER (
              Sales,
              Sales[product] = "iPhone"
      ))

      It works well, but when I add another filter it gives me (Blank) with card visual. I tried to copy and paste the the word to avoid case errors but still does not work. 

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

        Eesa ,Try this

        Smart Phones Sales =
        CALCULATE (
            SUM ( Sales[Price] ),
            FILTER (
                Sales,
                Sales[product] in { "iPhone","Samsung","Hawaii"}
        ))