Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
andrehawari
Helper II
Helper II

Measures That have Different Behaviour Between Category

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]))

 

forum.JPG

 

Thanks

 

1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

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:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-danhe-msft
Employee
Employee

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

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Employee
Employee

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:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
aaronwatt
Frequent Visitor

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.