Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Han_Solo
Helper I
Helper I

ALLSELECTED and CALCULATE inside SUMX vs plain CALCULATE

Hello,

while working on one report I've encountered two measures that I do not quite understand. 

 

Here's the sample of the data:

https://we.tl/t-Lgp69wQDVN

In general it looks like that and it goes with date (end of week) and Customer_ID

Han_Solo_0-1605775993424.png

 

This measure just counts the distinct values of Customer_ID dependent by the context. 

 

 

Unique_Customer_Simple = CALCULATE( DISTINCTCOUNT('dataset'[Customer_ID]))

 

 

 

This one, counts the distinct values of Customer_ID but taking down the context filter of date but keeping the outside filters. So for example if we would set month filter on only april and in matrix we would have only date column, it would show us total sum of distinct values of april for every date, do I get it right?

 

 

Unique_Customer_2 = CALCULATE( 
 DISTINCTCOUNT('dataset'[Customer_ID]), 
  ALLSELECTED('dataset'[Date] )
)

 

 

 

But what does this measure do? What is the difference between the above? I tried to play with it and it shows completely different values with CALCULATE inside the SUMX and without it. 

 

 

Unique_Customer_3 = 
VAR Total = SUMX( ALLSELECTED('dataset'[Date] ),
                    CALCULATE(DISTINCTCOUNT('dataset'[Customer_ID])))
RETURN Total

 

 

 

Thank you for help

Best Regards 

1 ACCEPTED SOLUTION
Han_Solo
Helper I
Helper I

IF anyone still wound be interested - 
mostly I needed to read 
https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/
and ALLSELECTED solutions from Definitive Guide to DAX. previous answers are mostly not useful at all. In general it's mostly about shadow context and how ALLSELECTED changes the context because of it's natural behavior. best would be to work on that personally but link will help a lot. 

 

 

 

View solution in original post

4 REPLIES 4
Han_Solo
Helper I
Helper I

IF anyone still wound be interested - 
mostly I needed to read 
https://www.sqlbi.com/articles/the-definitive-guide-to-allselected/
and ALLSELECTED solutions from Definitive Guide to DAX. previous answers are mostly not useful at all. In general it's mostly about shadow context and how ALLSELECTED changes the context because of it's natural behavior. best would be to work on that personally but link will help a lot. 

 

 

 

v-yiruan-msft
Community Support
Community Support

Hi @Han_Solo ,

Please review the following blog, hope it can help you can get a good understanding about CALCULATE and ALLSELECTED function.

How CALCULATE works in DAX

The definitive guide to ALLSELECTED

Best Regards
Community Support Team _ Rena Ruan
If this post helps, then please consider Accept it as the solution to help the other members find it more.

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

Sorry but that's not helpful. I understand the difference between sum and sumx. I just don't understand behaviour of allcalculated there. 


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors