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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sumitsingla12
Frequent Visitor

Help With DAX. How to get max value from aggregated value in Power bI DAX

Hi Folks,

 

I have a requirement where i need to calcualte the Average of subcategory sales values but there is another condition where i need to pick only those subcategories which have maximum sales in each category.

Here is the sample dataset where i have category column and subcategory column and sales. Now i want to pick one subcatgory from each catgory and respective sales for that subcategory and then do the average of it.

 

Desired result would be 98 in KPI Card. it will be something summarize over summarize because my subcategories value can also repeat. So first we need to aggregate category and subcategory sales and then take maximum for each subcategory and then derive averaga. Any opinion would be helpful

 

CatSubSales
C1S127
C1S28
C1S315
C1S485
C1S490
C2S564
C2S628
C2S712
C2S856
C3S948
C3S1011
C3S1044
2 ACCEPTED SOLUTIONS
rajendraongole1
Super User
Super User

Hi @sumitsingla12 - create a below measure, that will first aggregate the sales by subcategory within each category. you can replace with your tablename.

 

rajendraongole1_0-1726121101662.png

 

MaxSubcategorySales =
VAR SummaryTable =
    SUMMARIZE(
        'salesV',
        'salesV'[Cat],
        'salesV'[Sub],
        "Total Sales", SUM('salesV'[Sales])
    )
VAR MaxSalesTable =
    ADDCOLUMNS(
        SUMMARIZE(
            'salesV',
            'salesV'[Cat]
        ),
        "Max Sales", MAXX(FILTER(SummaryTable, 'salesV'[Cat] = EARLIER('salesV'[Cat])), [Total Sales])
    )
RETURN
AVERAGEX(MaxSalesTable, [Max Sales])
 
Hope it works.




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

Proud to be a Super User!





View solution in original post

sumitsingla12
Frequent Visitor

@rajendraongole1 Thank you so much . it seems to be working fine.

Can i ask u one more favour.  In this one we are doing average of same measure.

What if i have another measure lets say profit and i want to calcualte the sum of profit for those subcategory with maximum sales within a category.

 

View solution in original post

2 REPLIES 2
sumitsingla12
Frequent Visitor

@rajendraongole1 Thank you so much . it seems to be working fine.

Can i ask u one more favour.  In this one we are doing average of same measure.

What if i have another measure lets say profit and i want to calcualte the sum of profit for those subcategory with maximum sales within a category.

 

rajendraongole1
Super User
Super User

Hi @sumitsingla12 - create a below measure, that will first aggregate the sales by subcategory within each category. you can replace with your tablename.

 

rajendraongole1_0-1726121101662.png

 

MaxSubcategorySales =
VAR SummaryTable =
    SUMMARIZE(
        'salesV',
        'salesV'[Cat],
        'salesV'[Sub],
        "Total Sales", SUM('salesV'[Sales])
    )
VAR MaxSalesTable =
    ADDCOLUMNS(
        SUMMARIZE(
            'salesV',
            'salesV'[Cat]
        ),
        "Max Sales", MAXX(FILTER(SummaryTable, 'salesV'[Cat] = EARLIER('salesV'[Cat])), [Total Sales])
    )
RETURN
AVERAGEX(MaxSalesTable, [Max Sales])
 
Hope it works.




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

Proud to be a Super User!





Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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