Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
In a simple example where we have a dimension D_Entities with each dimension having some numeric Attribute, and a F_Comments table where each dimension might or might not have rows corresponding to it (1-many relationship over Name) - the goal is to calculate minimum Attribute value over all dimemsions that have corresponding rows.
Why on earth a simple measure doesn't work right:
Expected result for MinAttr measure is 100 because "A" dimension is the only dimension that has corresponding rows in F_Comments, and it's Attribute value is 100:
It's all on the screen, really:
Expanding on things said before..
I would leave the relationship as is, but change the measure to:
MinAttr = CALCULATE(
MIN(D_Entities[Attribute]),
F_Comments[Comment],
CROSSFILTER(D_Entities[Name],F_Comments[Name],Both)
)
Guys, thanks for the quick response, and we have at least several solutions that work:
Aesthetically, I'd take the first option - as it provides clearest code with minimal performance overhead, F_Comments being a relatively small "leaf" table. But maybe I'm wrong about performance here and one of the other options scales better? How to evaluate this?
@DmitryKo you can use the Server Timings or Query Plan features in DAX Studio.
Some sample resources:
https://www.youtube.com/watch?v=V_AHYAFuFs8
Enterprise DNA - Query Plan & Server Timings In DAX Studio
Actually your measure is roughly the opposite of the computation being tested in this recent article, so may be an interesting read:
https://www.sqlbi.com/articles/finding-products-without-sales-by-using-dax/
Hi @DmitryKo
In order to retrieve rows of D_Entities for which F_Comments is nonempty, you can use the SUMMARIZE function.
Here are some variations on how you could do this:
MinAttr =
CALCULATE (
MIN ( D_Entities[Attribute] ),
SUMMARIZE ( F_Comments, D_Entities[Name] )
-- Could also use SUMMARIZE ( F_Comments, D_Entities[Number] )
)
MinAttr =
-- SUMMARIZE F_Comments by D_Entities[Attribte]
-- then return the minimum
MINX (
SUMMARIZE ( F_Comments, D_Entities[Attribute] ),
D_Entities[Attribute]
)
MinAttr =
CALCULATE (
MIN ( D_Entities[Attribute] ),
F_Comments -- Apply the expanded F_Comments table as a filter
)
The reason for the original unintended result was that a filter on the F_Comments table does not itself filter the D_Entities table, due to the relationship direction.
Suggest reading some articles on expanded tables.
e.g. http://mdxdax.blogspot.com/2011/03/logic-behind-magic-of-dax-cross-table.html
or SQLBI will have some.
Regards
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |