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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Arjun_reddy
Helper I
Helper I

dax query

Hi Community team,

 

I have category, year, totalsales fields in sales table
I want to write a dax query - which category is having the highest value and what is the max value on total sales on category in max year
it should be return only which is the max value in category

please help me on my query

Thanks,

Arjun reddy

2 ACCEPTED SOLUTIONS

Hi @Arjun_reddy 
Sorry, I didn't see that you need it for the last year.
In this case the daxes are :
1. Basic sum of sales 

Sum of Sales = sum('Table'[sales])
2. Maximum sum of sales by category and last year :
Max Sales by Category and Last year =
VAR MaxSalesYear =
    MAX('Table'[year])

VAR CategorySales =
    SUMMARIZE(
        FILTER('Table', 'Table'[year] = MaxSalesYear),
        'Table'[Category],
        "TotalSales", [Sum of Sales]
    )

VAR MaxCategorySales =
    MAXX(CategorySales, [TotalSales])

RETURN
  MaxCategorySales
 
3. For Category 
MaxSalesCategory =
VAR MaxSalesYear =
    MAX('Table'[year])

VAR CategorySales =
    SUMMARIZE(
        FILTER('Table', 'Table'[year] = MaxSalesYear),
        'Table'[Category],
        "TotalSales", [Sum of Sales]
    )

VAR MaxCategorySales =
    MAXX(CategorySales, [TotalSales])

RETURN
    MAXX(
        FILTER(CategorySales, [TotalSales] = MaxCategorySales),
        [Category])
 
Result:
Ritaf1983_0-1691808771041.png

Link to a sample file 

Please consider Accepting it as the solution to help the other members find it more quickly

   
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Hi,

Please find attached the PBI file.

Hope this helps.

Ashish_Mathur_0-1691810700958.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Arjun_reddy
Helper I
Helper I

 

category

yearsales       
chairs20215000  result:    
tables20216000  The highest value having sofa     
bulbs20226000  the highest value is 9200     
sofa20224500       
chairs20228000       
chairs20216000       
chairs20212800       
sofa20224700       
bulbs20222000       
sofa20215500       
tables20216000       
tables20223400       

Hi,

Please find attached the PBI file.

Hope this helps.

Ashish_Mathur_0-1691810700958.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish Mathur,
I have implemented the same way to my report, its working fine, really awesome
Thanks a lot Ashish and Ritaf

You are welcome.  If my previous reply helped, please mark that reply as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Arjun_reddy  again 🙂
Please see my solution in the linked discussion :

https://community.fabric.microsoft.com/t5/Desktop/Count-Top-N/m-p/3375418#M1123600

It has a link to the sample file.

You can use the same logic with sum instead of count.
Let me know if it is clear, if not I will give you a solution with exactly your case.

Please consider Accepting it as the solution to help the other members find it more quickly

 

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

I gone through the process i made the query but its not given the correct result 

my query is which is the highest value on category on max year and the value should be display 

Hi @Arjun_reddy 
Sorry, I didn't see that you need it for the last year.
In this case the daxes are :
1. Basic sum of sales 

Sum of Sales = sum('Table'[sales])
2. Maximum sum of sales by category and last year :
Max Sales by Category and Last year =
VAR MaxSalesYear =
    MAX('Table'[year])

VAR CategorySales =
    SUMMARIZE(
        FILTER('Table', 'Table'[year] = MaxSalesYear),
        'Table'[Category],
        "TotalSales", [Sum of Sales]
    )

VAR MaxCategorySales =
    MAXX(CategorySales, [TotalSales])

RETURN
  MaxCategorySales
 
3. For Category 
MaxSalesCategory =
VAR MaxSalesYear =
    MAX('Table'[year])

VAR CategorySales =
    SUMMARIZE(
        FILTER('Table', 'Table'[year] = MaxSalesYear),
        'Table'[Category],
        "TotalSales", [Sum of Sales]
    )

VAR MaxCategorySales =
    MAXX(CategorySales, [TotalSales])

RETURN
    MAXX(
        FILTER(CategorySales, [TotalSales] = MaxCategorySales),
        [Category])
 
Result:
Ritaf1983_0-1691808771041.png

Link to a sample file 

Please consider Accepting it as the solution to help the other members find it more quickly

   
Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi @Arjun_reddy 
Glad to help 🙂
If our answers helped, please accept them as solutions, it will help to others to find them more quickly .

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Ritaf1983
Super User
Super User

Hi @Arjun_reddy 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors