Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

UNDERSTANDING CALCULATE FUNCTION

Hi Team,

 

I have the dataset as below

                              

Product Table

ColorFruitName 
Greenapples
Yellowbananas
Orangeoranges

Sales table

FruitName            OrderDate                  Week    Gender          Quantity SaleAmt

apples05-01-20172Male1010.14
apples05-01-20172Female2010.14
apples06-01-20172Female3520.28
bananas06-01-20172Male6320.28
bananas06-01-20172Male4120.28
apples07-01-20172Male2580.21
bananas07-01-20172Female6580.28
oranges07-01-20172Female9620.21

 

I have a measure 

Only Yellow Color Sales:=calculate(sumx(SalesB,SalesB[Quantity]*SalesB[SaleAmt]),ProductsB[Colour]="Yellow")

 

 

My question is why in the table am i not able to find the Fruite name for Color Green & Orange? However when i try to put another measure im getting the Fruitname

 

Yellow Color & Banana Fruit :=CALCULATE(sumx(SalesB,SalesB[Quantity]*SalesB[SaleAmt]),ProductsB[Colour]="Yellow",ProductsB[FruitName]="Bananas")

 

Can someone explain me this please?

 

 

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak i understand that having FILTER() inside calculate will get the table of only specified data ..However in my measures i havent used FILTER() ....I want to know why the fruit name is reflecting in one measure and not in another one?

  • Anonymous when you are giving DAX condition like this ProductsB[Colour]="Yellow", it removes the filter from the Color column and that's why you see repeated value for all the color. IN this case, it removes the filter on color column, and in 2nd example, it removes the row filter on both color and fruit, and that's why you see the fruit in all the lines.

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

     

  • v-luwang-msft's avatar
    v-luwang-msft
    Community Support

    Hi Anonymous ,

    When the second argument of CALCULATE is a boolean filter rather than a table of values, it is equivalent to FILTER(ALL(column), filter): that is: 

    CALCULATE(sumx('Sales table','Sales table'[Quantity]*'Sales table'[SaleAmt]),

    FILTER(ALL('Product Table'[Color]),'Product Table'[Color]="Yellow")).

     

     

     

    And CALCULATE does indeed override the filter context when evaluating its first argument; using the rows provided to its second argument as the new filter context. However; CALCULATE does not alter the filter context when evaluating its second argument, and so pre-existing filters remain unless they are explicitly removed.
     
     
     
     
    Best Regards
    Lucien
  • v-luwang-msft's avatar
    v-luwang-msft
    Community Support

    Hi Anonymous ,

    Has your problem been solved, if so, please consider Accept a correct reply as the solution or share your own solution to help others find it.

    Best Regards
    Lucien