Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Wondering if anyone can assist
Have a table with values of keys, count and value
Need to group by Key and determine the distinct count and get the max value for each
Once done, except the the highest Max and if 0, determine the average of all values above based on the Key
Wondering how to come up with a DAX Query for this in POWER BI
Hi @avidthinker ,
Please try the measure.
Measure =
VAR maxvalue =
CALCULATE ( MAX ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Key] ) )
VAR maxvalue_count =
CALCULATE ( MIN ( 'Table'[Count] ), ALL ( 'Table' ), 'Table'[Value] = maxvalue )
RETURN
CALCULATE (
AVERAGE ( 'Table'[Value] ),
FILTER (
ALL ( 'Table' ),
'Table'[Key] = MAX ( 'Table'[Key] )
&& 'Table'[Value] <> 0
&& 'Table'[Count] <> maxvalue_count
)
)
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi v-kkf-msft,
I tried your calculations, but does not seem quite right.
To simplify,this is what is required, ignore Count 0 and Value 0 and only consider for now AAA once correct, need to work out for original with multiple Key Values.
| Key | Count | Value |
| AAA | 0 | 0 |
| AAA | 1 | 1000 |
| AAA | 1 | 1100 |
| AAA | 1 | 1200 |
| AAA | 2 | 2000 |
| AAA | 2 | 2100 |
| AAA | 2 | 2200 |
| AAA | 3 | 3000 |
| AAA | 3 | 3100 |
For AAA, the count is 1,2 values max 1200,2200
max of 2, max total of 3400
average will be 3400/2=1700
Hope this helps
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 9 | |
| 8 | |
| 8 |