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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Buckswriter
Frequent Visitor

Rolling Counts

Hi.

 

I am struggling to know which is the best way to add a column to my data which will produce a count of how many times a value appears; I don't want a simple count - what I am after is a formula which will increment by 1 each time another instance of the value appears in the given column.

 

The images below are simply a sample - if I can undrstand the principle on some basic data, my theory is that I can then develop my learning and make more contextual using filters as I go on, but for now I just need to know the basic technique and formula.

 

OK, the first image is my data in Excel, but with a column showing the count of names in column A, i.e. each time a new instance of the name is encountered in column 'Name', the count goes up by 1. 

 

The other images show my data source file (but with the formula 'in progress', so that you can see what it does.

 

The third image is how my data file looks in Power BI, i.e. with no 'Count of Name' column.

 

Ultimately I want to have a calculated column that shows the count of each name, so that I can then use another formula to extract the 5 most recent instances, i.e. the 5 most recent rows for each name.

 

Screenshot 2021-09-27 183337.pngScreenshot 2021-09-27 182818.pngScreenshot 2021-09-27 182525.png

 

 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Picture2.png

 

Count of Name CC : =
VAR currentname = Data[Name]
VAR currentdate = Data[Date]
RETURN
COUNTROWS (
FILTER ( Data, Data[Name] = currentname && Data[Date] <= currentdate )
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@Buckswriter 

Add this new column to your table:

Count = 
COUNTROWS(
    SELECTCOLUMNS( FILTER( Table1 , Table1[Date] <= EARLIER(Table1[Date]) && Table1[Name] = EARLIER(Table1[Name])) , "Name" , Table1[Name] )
)

Fowmy_0-1632765024664.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Jihwan_Kim
Super User
Super User

Picture2.png

 

Count of Name CC : =
VAR currentname = Data[Name]
VAR currentdate = Data[Date]
RETURN
COUNTROWS (
FILTER ( Data, Data[Name] = currentname && Data[Date] <= currentdate )
)

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

jaideepnema
Solution Sage
Solution Sage

Hi @Buckswriter ,
Can you paste this data here instead of sharing the image so that we can check this ?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors