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

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.

Reply
Ainala
Frequent Visitor

SUM and MAX of sales based on flag

Hello Power Users,
I'm trying to create a dax measure for below table structure. If the Flag = Y then take max of sales  and if flag = "N" then sum of sales for all the months.

 

YearMonthCustomerSalesFlag
20221ABC100N
20222ABC55N
20223ABC110N
20221XYZ110Y
20222XYZ110Y
20223XYZ110Y

 

I have Year and Customer slicers on the page. 

How can we achive this.  Please help.

 

Thanks

1 ACCEPTED SOLUTION
negi007
Community Champion
Community Champion

@Ainala 

create below measure

Max_sales = CALCULATE(MAX(Tab[Sales]),Tab[Flag]="Y")
Sum_sales = CALCULATE(SUM(Tab[Sales]),Tab[Flag]="N")
 
then create a calculated column 
Sales_New = if(Tab[Flag]="Y",[Max_sales],[Sum_sales])
 
negi007_0-1655305177123.png

 

negi007_1-1655305248385.png

 

let me know if this is what you want.




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Ainala 

Please try measure as below:

Measure = SWITCH(MAX('Table'[Flag]),"N",SUM('Table'[Sales]),"Y",MAX('Table'[Sales]))

If it does't work, please provide more details for further investigation.

Best Regards,
Community Support Team _ Eason

negi007
Community Champion
Community Champion

@Ainala 

create below measure

Max_sales = CALCULATE(MAX(Tab[Sales]),Tab[Flag]="Y")
Sum_sales = CALCULATE(SUM(Tab[Sales]),Tab[Flag]="N")
 
then create a calculated column 
Sales_New = if(Tab[Flag]="Y",[Max_sales],[Sum_sales])
 
negi007_0-1655305177123.png

 

negi007_1-1655305248385.png

 

let me know if this is what you want.




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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