How to check which of the two DAX queries has a better performance using Daxstudio. In the example the queries return exactly the same results. However the stats differ showing not clear hints. What usuful information can we grasp from the comparison of the two queries?
Comparison query stats summary:
+-------------------------+------------+---------+---------+
| | | Query 1 | Query 2 |
+-------------------------+------------+---------+---------+
| Server timings | Total | 7 | 5 |
| | SE CPU | 0 | 0 |
| | FE | 6 | 4 |
| | SE | 1 | 1 |
| | SE Queries | 3 | 2 |
| | SE Cashe | 0 | 0 |
+-------------------------+------------+---------+---------+
| Query plan, no of lines | physical | 7 | 28 |
| | logical | 13 | 9 |
+-------------------------+------------+---------+---------+
- The second query is quicker but has a bushy and longer plan. 2 scans.
- The first query has longer server timings but cleaner and shorter query plan. 3 scans.
So the server timings favor the second query but its complex query plan raises concern. Knowing the stats and query plans what can we expect if the SearchTable had milion of rows? Shouldn't we like simpler query plans, since DAX optimization may change in the future in their favor?
Sample data. We have two tables SearchTable and ThisTable:
SearchTable =
DATATABLE (
"Category", STRING,
"Product", STRING,
"Amount", INTEGER,
{
{ BLANK () , "apple" , 1 },
{ "Fruits" , "apple" , 1 }, -- watch out for multiple apples!
{ "Yummy Fruits", "apple" , 2 },
{ "Fruits" , "banana" , 4 },
{ "Fruits" , "wolfberry" , 5 },
{ "Fruits" , "cherry" , 3 },
{ "Vegetables" , "carrot" , 3 },
{ "Vegetables" , "potato" , 1 },
{ "Vegetables" , "onion" , 7 },
{ "Fruits" , "cherry" , 3 }
}
)
---
ThisTable =
DATATABLE (
"Product", STRING,
{
{ "apple" },
{ "banana" },
{ "blackberry" },
{ "carrot" },
{ "cherry" },
{ "onion " },
{ "potato" },
{ "watermelon" },
{ "wolfberry" }
}
)
Query no 1.
EVALUATE
ADDCOLUMNS (
VALUES ( ThisTable[Product] ),
"FilterLookup",
VAR LookupKey = ThisTable[Product]
RETURN
CALCULATE ( MAX ( SearchTable[Category] ), SearchTable[Product] = LookupKey )
)
The query has these stats:
Query no 2.
EVALUATE
ADDCOLUMNS (
VALUES ( ThisTable[Product] ),
"FilterLookup", MAXX (
FILTER ( SearchTable, SearchTable[Product] = ThisTable[Product] ),
SearchTable[Category]
)
)
The question is related to:
DAX lookup first non blank value in unrelated table
You can download a pbix file with sample data: