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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
jabrillo
Helper I
Helper I

Count Categories of Similar Sums

Table 1 - Sample data

CategorySub-CategoryAllocation
A100.5
A200.5
B100.75
C100.5
C200.25
D100.25
D200.25
D300.25
E301.0

 

Table 2 - Sum by Category (using Table visual)

CategorySum of Allocation
A1.0
B0.75
C0.75
D0.75
E1.0

 

Table 3 - Count of Category by Sum of Allocation

Sum of AllocationCount
0.753
1.02

How can I produce the third table? I tried using calculate(sum(allocation, filter(table, category = earlier(category)))), but the result sums all allocations.

3 REPLIES 3
ERD
Community Champion
Community Champion

@jabrillo , from your example and provided demo table:

1. Create a calculated column in your data table:

Allocation per category = 
CALCULATE ( SUM ( T[Allocation] ), ALLEXCEPT ( T, T[Category] ) )

2. Create a measure:

Allocation Count = 
VAR __t = SUMMARIZE ( T, T[Category], T[Allocation per category] )
VAR __t2 = SUMMARIZE ( T, T[Category], T[Sub-Category], T[Allocation] )
RETURN
    IF (
        ISFILTERED ( T[Sub-Category] ),
        COUNTAX ( __t2, [Category] ),
        COUNTAX ( __t, [Category] )
    )

ERD_0-1696003657246.png 

ERD_1-1696003672092.png

 

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

tackytechtom
Super User
Super User

Hi @jabrillo ,

 

Here a solution by creating a calculated table using DAX:

tackytechtom_0-1695837013590.png

 

Here the code for the calculated table:

New Table = 
VAR _helpTable =
SUMMARIZE (
    'Table',
    'Table'[Category],
    "Sum of Allocation", SUM ( 'Table'[Allocation] )
)
RETURN
SUMMARIZE (
    _helpTable,
    [Sum of Allocation],
    "Count",
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Category] ),
        FILTER (
            VALUES ( 'Table'[Category] ),
            CALCULATE ( SUM ( 'Table'[Allocation] ) ) = [Sum of Allocation]
        )
    )
)

 

I did something similar explained here:

https://www.tackytech.blog/how-to-crack-the-mystery-of-the-mighty-dax/#count-occurrence-of-attribute...

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

I tried it and I was hoping the slicers would be in effect, but they weren't. The sample data has other columns with associated slicers. I tried to use a filtered table on the first SUMMARIZE but it didn't work. On the second SUMMARIZE, shouldn't I just count the 'Table'[Category] from the first SUMMARIZE? I tried this:

SUMMARIZE (
    _helpTable,
    [Sum of Allocation],
    "Count",
    distinctcount('Resource Allocation'[Res Name])
but this didn't work too.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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