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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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