Forum Discussion

andrehawari's avatar
andrehawari
Icon for Helper II rankHelper II
7 years ago
Solved

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

 

 

Thanks

 

3 Replies

  • aaronwatt's avatar
    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

  • v-danhe-msft's avatar
    v-danhe-msft
    Icon for Microsoft Employee rankMicrosoft 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