Forum Discussion
Arjun_reddy
3 years agoHelper 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 ca...
- 3 years ago
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 salesSum 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])RETURNMaxCategorySales3. For CategoryMaxSalesCategory =VAR MaxSalesYear =MAX('Table'[year])VAR CategorySales =SUMMARIZE(FILTER('Table', 'Table'[year] = MaxSalesYear),'Table'[Category],"TotalSales", [Sum of Sales])VAR MaxCategorySales =MAXX(CategorySales, [TotalSales])RETURNMAXX(FILTER(CategorySales, [TotalSales] = MaxCategorySales),[Category])Result:Please consider Accepting it as the solution to help the other members find it more quickly
- 3 years ago
Hi,
Please find attached the PBI file.
Hope this helps.
Ritaf1983
3 years agoSuper User
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:
Please consider Accepting it as the solution to help the other members find it more quickly
Ritaf1983
3 years agoSuper User
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 .