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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jstein91694
Frequent Visitor

Indexing a Column for Cycles by Day

Hello!

I have a column of data that is either a 0 or a 1, which is basically showing on/off. I would like to index the 1's for each day to show the number of cycles per day.

For example, a column of this [0,0,0,1,0,0,0,0,1,0,0,1]

Would become [0,0,0,1,1,1,1,1,2,2,2,3].

When the date changes to the next day, the index would reset to 0.

Thanks for the help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @jstein91694 ,

 

First create an index column:

Go to query editor>add column>index column;

Then create a calculated column as below:

 

Column 2 = 
var _date=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
Return
IF('Table'[Date]<>_date,0,IF('Table'[Column]<>0,RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])&&'Table'[Column]=1),'Table'[Index],,ASC,Dense),RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])&&'Table'[Column]=1),'Table'[Index],,ASC,Dense)-1))

 

And you will see;

Annotation 2020-06-22 141643.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi  @jstein91694 ,

 

First create an index column:

Go to query editor>add column>index column;

Then create a calculated column as below:

 

Column 2 = 
var _date=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
Return
IF('Table'[Date]<>_date,0,IF('Table'[Column]<>0,RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])&&'Table'[Column]=1),'Table'[Index],,ASC,Dense),RANKX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])&&'Table'[Column]=1),'Table'[Index],,ASC,Dense)-1))

 

And you will see;

Annotation 2020-06-22 141643.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@jstein91694 , you need to have index or incremental column or date and post that you can have formula like

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

sumx(filter(Table,[index] <=earlier([index])),[column])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Hi @jstein91694 

if your data is ordered with DateTime column, try create a new column

Column = CALCULATE(SUM('Table'[Column1]), FILTER(ALLEXCEPT('Table', 'Table'[DateTime].[Date]), 'Table'[DateTime] <= EARLIER('Table'[DateTime])))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
lbendlin
Super User
Super User

Just do a running total sum of the column per day. Free index!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.