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
rtaylor
Helper III
Helper III

Difference in values for seeming same measures

Can anyone share any insight as why these dax measures have different results? I can't find any literature on why this would be the case. I've noticed the phenomena twice so far.
First Measure set
1. Occupancy Residency Count_. =
CALCULATE (
    [Source.StarRez.DistinctCountofRedIds],
    FILTER (
        OccupancyInfo,
        OccupancyInfo[Check In Date] <= MIN ( 'Date'[Date] )
            && OccupancyInfo[Check Out Date] >= MIN ( 'Date'[Date] )
    ),
    OccupancyInfo[Entry Status Description 5] <> "Cancelled"
)
 
Occupancy Count YTD_. =
2. MAXX ( SUMMARIZE ( 'Date', 'Date'[Date] ), [Occupancy Residency Count_.] )
 
Second Measure.
 
Occupancy Count YTDRemake =
VAR occu =
CALCULATE (
[Source.StarRez.DistinctCountofRedIds],
FILTER (
OccupancyInfo,
OccupancyInfo[Check In Date] <= MIN ( 'Date'[Date] )
&& OccupancyInfo[Check Out Date] >= MIN ( 'Date'[Date] )
),
OccupancyInfo[Entry Status Description 5] <> "Cancelled"
)
RETURN
MAXX ( SUMMARIZE ( 'Date', 'Date'[Date] ), occu )
1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User


@rtaylor wrote:
Can anyone share any insight as why these dax measures have different results? I can't find any literature on why this would be the case. I've noticed the phenomena twice so far.
 
 

The reason is that variables are calculated once within the scope where they are defined. So in your second measure set the "occu" variable will be calculated once for all dates in the current context, this makes the MAXX(SUMMARIZE(...)) call redundant as occu will have the same value for every row.

 

Whereas in the first measure set when you reference one measure within the summarize in the second measure the expression is re-evaluated within the context of the summarize.

View solution in original post

5 REPLIES 5
d_gosbell
Super User
Super User


@rtaylor wrote:
Can anyone share any insight as why these dax measures have different results? I can't find any literature on why this would be the case. I've noticed the phenomena twice so far.
 
 

The reason is that variables are calculated once within the scope where they are defined. So in your second measure set the "occu" variable will be calculated once for all dates in the current context, this makes the MAXX(SUMMARIZE(...)) call redundant as occu will have the same value for every row.

 

Whereas in the first measure set when you reference one measure within the summarize in the second measure the expression is re-evaluated within the context of the summarize.

Thank you for the reply. That makes the most sense. Is there anyway to contain the entire formula within a variable and retrieve the same result?

 

Thanks Again

So if you don't want to have 2 separate measures you should be able to insert the calculate() from the first measure into the second as follows. Note, I changed the summarize() to an addcolumns() as it's a safer pattern for an inlined measure like this (the guys at sqlbi.com have an article on why to use addcolumns instead of summarize)

 

 

Occupancy Count YTD_. =
MAXX (
ADDCOLUMNS (
VALUES ( 'Date'[Date] ),
"Occupancy Residency Count_.",
CALCULATE (
[Source.StarRez.DistinctCountofRedIds],
FILTER (
OccupancyInfo,
OccupancyInfo[Check In Date] <= MIN ( 'Date'[Date] )
&& OccupancyInfo[Check Out Date] >= MIN ( 'Date'[Date] )
),
OccupancyInfo[Entry Status Description 5] <> "Cancelled"
)
),
[Occupancy Residency Count_.]
)

 

 

You could wrap the whole thing in a variable, but you would not really gain any benefit from that as you are not breaking down the calculation into smaller pieces or reusing the variable. It's probably better to just have 2 measures if you can re-use the first measure anywhere or to just inline the calculation as above. 

 

Occupancy Count YTD_. =
 VAR _result = MAXX (
ADDCOLUMNS (
VALUES ( 'Date'[Date] ),
"Occupancy Residency Count_.",
CALCULATE (
[Source.StarRez.DistinctCountofRedIds],
FILTER (
OccupancyInfo,
OccupancyInfo[Check In Date] <= MIN ( 'Date'[Date] )
&& OccupancyInfo[Check Out Date] >= MIN ( 'Date'[Date] )
),
OccupancyInfo[Entry Status Description 5] <> "Cancelled"
)
),
[Occupancy Residency Count_.]
) RETURN _result

 

 

Hello,

 

I'm sorry it took me such a long time to reply.

 

Thank you for comments. My endgame for all of this is to speed up calculation. Right now it takes almost 25 seconds for the calcuation to complete. I'm hoping to get down to 15.

 

Also I tried your solution and still getting the incorrect display.image.png

Greg_Deckler
Super User
Super User

I actually do not believe either is correct. It seems like what you really want is this:

 

MAXX ( SUMMARIZE ( 'Date', 'Date'[Date], "__occu",[Occupancy Residency Count_.]),[__occu])

For the 2nd one you would want:

MAXX ( SUMMARIZE ( 'Date', 'Date'[Date], "__occu",occu),[__occu])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.