Forum Discussion
Sum values for each category
- 1 year ago
Hi,
I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
Order count: = SUMX ( VALUES ( Fruit[Fruit] ), COUNTROWS ( CALCULATETABLE ( FILTER ( SUMMARIZE ( Data, Data[Customer ID], Data[Order Date], Data[quantity] ), Data[quantity] > 0 ) ) ) )
Hi warabimochi
To calculate the total OrderCount for each fruit in Power BI using DAX, you can create a calculated measure or a calculated column depending on how you want to aggregate the data.
1. Create a Measure
If you want to dynamically calculate the total OrderCount for each fruit when visualized, you can use the following DAX formula:
Total OrderCount = SUM('Table'[OrderCount])
This measure will sum up the Or
derCount column for all rows in your table. When you create a visual (e.g., a bar chart or table), place Fruit on the axis and this measure in the values to see the totals grouped by fruit.
2. Create a Calculated Column (if needed)
If you want to calculate the total OrderCount for each fruit within the table itself, you can use this formula in a calculated column:
Total OrderCount by Fruit =
CALCULATE(
SUM('Table'[OrderCount]),
ALLEXCEPT('Table', 'Table'[Fruit])
)
This will create a column where the total OrderCount for each fruit is shown for every row corresponding to that fruit.
3. Create a Summary Table (Optional)
If you'd like to create a summary table displaying only the fruit and their respective OrderCount, you can use the following DAX to create a new table:
Fruit Order Summary =
SUMMARIZE(
'Table',
'Table'[Fruit],
"Total OrderCount", SUM('Table'[OrderCount])
)
This creates a new table where each row contains a unique fruit and its total OrderCount.
Expected Output
With the given dataset, the output would be:
Fruit Total OrderCount
| Orange | 3 |
| Banana | 4 |
| Apple | 4 |
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS