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!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Hi
I have the following table below.
Basically I want to create the measure that have following behaviour,
IF, Category=A, then average(Sales) else
IF Category=B, then sum(Sales).
I have created the following dax query, but it gave me a wrong result
IF ( max(Table1[Category])=A, AVERAGE(Table1[Sales]), sum(Table1[Sales]))
Thanks
Solved! Go to Solution.
Hi @andrehawari,
Based on my test, you could refer to below formula:
Measure = IF(MAX('Table1'[Category])="A",CALCULATE(AVERAGE(Table1[Sales]),ALL(Table1)),CALCULATE(SUM(Table1[Sales]),ALL(Table1)))
Result:
You could also download the pbix file to have a view.
Regards,
Daniel He
Hi @andrehawari,
Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?
Regards,
Daniel He
Hi @andrehawari,
Based on my test, you could refer to below formula:
Measure = IF(MAX('Table1'[Category])="A",CALCULATE(AVERAGE(Table1[Sales]),ALL(Table1)),CALCULATE(SUM(Table1[Sales]),ALL(Table1)))
Result:
You could also download the pbix file to have a view.
Regards,
Daniel He
This should give you the correct results
SalesMeas =
MAXX (
KEEPFILTERS ( VALUES ( 'Table1'[Category] ) ),
CALCULATE (
IF (
GROUPBY ( Table1, Table1[Category] ) = "A",
AVERAGE ( Table1[Sales] ),
SUM ( Table1[Sales] )
)
)
)
Aaron
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 64 | |
| 53 | |
| 42 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 122 | |
| 104 | |
| 45 | |
| 31 | |
| 24 |