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! Request now

Reply
francomaestri
Frequent Visitor

Cumulative count by categories

Greetings,

 

I'm trying to count the occurrence of certain events on some dates, but I can't calculate it correctly, so when I create a chart, the occurrence of a new event (new category) starts from zero. That is, each line on the chart starts from zero the first time it appears.

 

This is what I have so far: 

(Table as an example)

DateCategory
08-07-2022A
08-07-2022B
08-07-2022A
14-08-2022A
14-08-2022C
09-09-2022C
09-09-2022A
09-09-2022B
09-09-2022B

 

COUNTING = CALCULATE( COUNTROWS('Table'),FILTER(ALL('Table'), 'Table'[Category] <= MAX('Table'[Category]) && 'Table'[Date] <= MAX('Table'[Date])))
francomaestri_0-1668871866636.png

 

1 ACCEPTED SOLUTION
francomaestri
Frequent Visitor

Ok, I solved it.

I just created an index in power query, then I created a new column with rankx:

 

Count with rankx= RANKX(
    FILTER ( 'Table', 'Table'[Category] = EARLIER ( 'Table'[Category] ) ),
    'Table'[Index], ,ASC )

 

Then I just put Date in X-axis, the new column in Y-axis and Category in legend.
This way I can see when a new event occurs and how many times is repeated over time an when.

francomaestri_0-1668898650989.png

 

View solution in original post

7 REPLIES 7
francomaestri
Frequent Visitor

Ok, I solved it.

I just created an index in power query, then I created a new column with rankx:

 

Count with rankx= RANKX(
    FILTER ( 'Table', 'Table'[Category] = EARLIER ( 'Table'[Category] ) ),
    'Table'[Index], ,ASC )

 

Then I just put Date in X-axis, the new column in Y-axis and Category in legend.
This way I can see when a new event occurs and how many times is repeated over time an when.

francomaestri_0-1668898650989.png

 

mangaus1111
Solution Sage
Solution Sage

Hi @francomaestri ,

if it were a table is this your expected result? If not, please show what is your expected result.

mangaus1111_0-1668885862917.png

 

Hi!
I think that the result in a table would be:

DateCategoryCount
08-07-2022A1
08-07-2022B1
08-07-2022A2
14-08-2022A3
14-08-2022C1
09-09-2022C2
09-09-2022A4
09-09-2022B2
09-09-2022B3

 

If I'm not mistaken, in this way in the graph, for example, the line of category C will start at 1 on 08-14-2022. I could just split each event type (category) into a different column, but the category of events may change in the future, so I wanted to keep the table as it is (also because there are many more columns than shown here).

 

FreemanZ
Super User
Super User

If there is no misunderstanding, you measure shall be like this:
COUNTING = 
VAR CurrentDate = MAX('Table'[Date])
RETURN
CALCULATE( 
    COUNTROWS('Table'),
    FILTER(
        ALL('Table'), 
        'Table'[Date] <= CurrrentDate
    )
)
 
The [Category] field shall be put in the Legend of the linechart visual, or?

I'm having the same problem. When a new event appears it does not start from zero.

francomaestri_1-1668883442584.png

 

Jayee
Responsive Resident
Responsive Resident

Hi @francomaestri 

 

Counting =

VAR MaxDate = MAX ( 'Table'[Date] ) 

RETURN

    CALCULATE (

        COUNTROWS('Table'),

        'Table'[Date] <= MaxDate,

        ALL ( Table )

    )

 

Use this measure in chart and add Category as legend.

 

If this post helps, then please consider Accept it as the solution, Appreciate your Kudos!!

 

Sadly I'm having the same problem. Each new event starts from a higher value, not from zero.

francomaestri_0-1668883325970.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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