DAX formula - Cumulative Count

Vaslo

Board Regular
Joined
Jun 3, 2009
Messages
159
Hello,

I am trying to do something like this: I have a column with names of cities:

Richmond
Cleveland
Cleveland
Boston
Cleveland
Boston

I would like a cumulative count down the column in PowerPivot:

Richmond 1
Cleveland 1
Cleveland 2
Boston 1
Cleveland 3
Boston 2

I have tried the following, but it just returns the total count to each matching row:

Code:
=CALCULATE (
    COUNTROWS ( CityList ),
    FILTER (
        CityList,
        CityList[CityName]
            = EARLIER ( CityList[CityName]
 )
    )
)

Thanks in advanced!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
First: this will work only in calculated column
Second: it requires index column

Code:
=CALCULATE (
    COUNTROWS ( CityList ),
    FILTER (
        CityList,
        CityList[CityName]
            = EARLIER ( CityList[CityName]) && CityList[Index] <= EARLIER(CityList[Index])
 
    )
)
 
Upvote 0
That did it, many thanks. Don't have a great understanding of the EARLIER formula, and definitely had no idea you could even do a 3 item equality check like that.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top