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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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 an 8 times 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 an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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