cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bustardo Regular Visitor
Regular Visitor

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

Accepted Solutions
Super User
Super User

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

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
Highlighted
Bustardo Regular Visitor
Regular Visitor

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

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]))
Super User
Super User

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

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

Bustardo Regular Visitor
Regular Visitor

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

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
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (4,355)