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.
Solved! Go to Solution.
@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.
@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.
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])
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |