cancel
Showing results for
Did you mean:
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.
3 REPLIES 3
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.
Helper I

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.

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.

Announcements

#### 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.