Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi Community,
I am having the below measure which will give the "Top Competitor" .Whenever I use this measure in the visual its causing high latnecy.It would be of great help if you guide me to optimise the below dax!! 🙂
Please note that I am using live connection type to AAS.
Country | Product | Brand | Top Competitor |
United States | aaa | zzz | pqr |
Any help in this regard would be much appreaciated!!
Thank You
Solved! Go to Solution.
// You can try this... but of course I have no access
// to your data, so it's only based on my "what I think
// I could do"... One can't really do any DAX tuning without
// access to the model/data. And your DAX will never be fast
// if the SQL it creates is not. You also have to have a look
// at the generated SQL and tune your tables accordingly.
Top Competitor =
VAR TimeCalculation =
SELECTEDVALUE( 'Time'[TimeCalculation] )
var ManufacturersOfInterest =
FILTER(
ALLSELECTED( 'Manufacturer'[Manufacturer] ),
NOT 'Manufacturer'[Manufacturer] IN {
"abc",
"xyz"
}
)
VAR Manuf =
ADDCOLUMNS(
ManufacturersOfInterest,
"@TotalValue", // This will likely be a spoiler...
CALCULATE(
SUM( 'Sales'[Sales] ),
'Time'[Offset] = 0,
'Time '[TimeCalculation] = TimeCalculation,
ALL( 'Time' ),
ALL( Brand )
)
)
VAR Top1Manufacturer =
MAXX(
TOPN(
1,
FILTER(
Manuf,
[@TotalValue] <> 0 // Change to > 0 if possible
),
[@TotalValue], DESC
),
'Manufacturer'[Manufacturer]
)
RETURN
Top1Manufacturer
// You can try this... but of course I have no access
// to your data, so it's only based on my "what I think
// I could do"... One can't really do any DAX tuning without
// access to the model/data. And your DAX will never be fast
// if the SQL it creates is not. You also have to have a look
// at the generated SQL and tune your tables accordingly.
Top Competitor =
VAR TimeCalculation =
SELECTEDVALUE( 'Time'[TimeCalculation] )
var ManufacturersOfInterest =
FILTER(
ALLSELECTED( 'Manufacturer'[Manufacturer] ),
NOT 'Manufacturer'[Manufacturer] IN {
"abc",
"xyz"
}
)
VAR Manuf =
ADDCOLUMNS(
ManufacturersOfInterest,
"@TotalValue", // This will likely be a spoiler...
CALCULATE(
SUM( 'Sales'[Sales] ),
'Time'[Offset] = 0,
'Time '[TimeCalculation] = TimeCalculation,
ALL( 'Time' ),
ALL( Brand )
)
)
VAR Top1Manufacturer =
MAXX(
TOPN(
1,
FILTER(
Manuf,
[@TotalValue] <> 0 // Change to > 0 if possible
),
[@TotalValue], DESC
),
'Manufacturer'[Manufacturer]
)
RETURN
Top1Manufacturer
Thank alot for the reply😊
This solution works perfectly and solved the problem.
Cheers😀
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
41 | |
19 | |
19 | |
15 | |
15 |
User | Count |
---|---|
49 | |
26 | |
22 | |
17 | |
16 |