cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bustardo
Helper I
Helper I

Can someone please tell me why this Dax Statement doesn't behave as expected? (for me)

Hi,

I'm fairly new to Dax and I'm curious why one piece of code works the way I'd expect, but the other does not.

 

 

I have a measure:

 

 

 

 

TM Num X:=
      Calculate(Distinctcount([UserID]),
      Filter(factTable,   [TM Denom] = 1  && not(isblank([ShipDate]))),
     (DATESBETWEEN(DimDate[Date],[FYSTARTDATE],[FYENDDATE]))
   ,USERELATIONSHIP(DimDate[Date],factTable[ShipDate])

Which doesn't work, however, when I do this, I get the desired result, I just have to use 2 measures.

 

TM Num X:=
   Calculate(Distinctcount([UserID]),
 Filter(factTable,   [TM Denom] = 1  && not(isblank([ShipDate]))),(DATESBETWEEN(DimDate[Date],[FYSTARTDATE],[FYENDDATE])))


TMX2:=
[TM Num X] (USERELATIONSHIP(DimDate[Date],factTable[ShipDate]))

Can someone please explain why the first one doesn't work?

1 ACCEPTED SOLUTION

I don't really understand the formulas in the Original post. The second formula  isnt invalid.  I assume it is supposed to be a calculate. The second post doesn't even contain the userelationships part, so I don't see how it can give the same result. 

 

The filter portion of calculate operates in the current filter context. 

 

Regarding the first formula in the first post.

the use relationships portion is applied at the same time as the filter portion. Use relationships is applied with filter, not TO filter 

 

Regarding the second set of formulas in the first post 

 Your second formula applies the inactive relationship first, then executes the first formula.  As a result, the first formula operates in a filter context with the new relationship applied already

 



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

3 REPLIES 3
Bustardo
Helper I
Helper I

Rewriting it like this gives the desired result, I'm thinking it may have to do with filter/row context but I still am unsure why i get bad numbers in the original statement.

 

Edited:

TM Num X:=
Calculate(Distinctcount([UserID]),
[TM Denom] = 1 , not(isblank([ShipDate]))), USERELATIONSHIP(DimDate[Date],FactTable[ShipDate]),((DATESBETWEEN(DimDate[Date],[FYSTARTDATE],[FYENDDATE]))

I don't really understand the formulas in the Original post. The second formula  isnt invalid.  I assume it is supposed to be a calculate. The second post doesn't even contain the userelationships part, so I don't see how it can give the same result. 

 

The filter portion of calculate operates in the current filter context. 

 

Regarding the first formula in the first post.

the use relationships portion is applied at the same time as the filter portion. Use relationships is applied with filter, not TO filter 

 

Regarding the second set of formulas in the first post 

 Your second formula applies the inactive relationship first, then executes the first formula.  As a result, the first formula operates in a filter context with the new relationship applied already

 



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

Sorry, I was retyping it from memory on my mobile and I forgot to include that, so of course it didn't make sense. Thanks for your reply. I've only been using DAX for about a week.

 

Can you please explain "

Regarding the first formula in the first post.

the use relationships portion is applied at the same time as the filter portion. Use relationships is applied with filter, not TO filter " a bit more?

 

Thanks! I'll mark it as the answer.

 

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors