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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How to reset a measure counter depending on other column data

Hi all,

 

I've trying to automate the calculation showed below in the last column "Batch Number of Campaign" and no way can I get it right.

 

The counter starts from 1 in the first batch and continue incrementing by one when "Batch changes" and resets when there is a "CF" in product.

 

Can anybody give me some advise please? Thanks a lot!

 

ProductBatchShiftDateBatch Number of Campaign
Product A7H2S2.M07-01-20201
Product A7H2S3.T07-01-20201
Product A7H2S1.N08-01-20201
Product A7H3L2.M08-01-20202
Product A7H3L3.T08-01-20202
Product A7H3L1.N09-01-20202
Product A7H3P2.M09-01-20203
Product A7H3P3.T09-01-20203
CF47H3P3.T09-01-20200
Product B848E1.N10-01-20201
Product B848E2.M10-01-20201
Product B848E2.M13-01-20201
Product B848E3.T13-01-20201
Product B848F1.N14-01-20202
Product B848F2.M14-01-20202
Product B848F3.T14-01-20202
Product B848F1.N15-01-20202
Product B848F2.M15-01-20202
CF2848F2.M15-01-20200
CF2848F3.T15-01-20200
Product C9P9X3.T15-01-20201
Product C9P9X1.N16-01-20201
Product C9P9X2.M16-01-20201
Product C9P9X3.T16-01-20201
Product C9P9X1.N17-01-20201
Product C9P9X2.M17-01-20201
Product C9P9X3.T17-01-2020

1

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous,

 

Create a calculated column as below:

 

Batch Number of Campaign = 
var _CFcheck=SEARCH("CF",'Table'[Product],1,BLANK())
Return
IF(_CFcheck=1,0,RANKX(FILTER('Table','Table'[Product]=EARLIER('Table'[Product])),'Table'[Batch],,ASC,Dense))

 

Finally you will see:

Annotation 2020-06-17 105635.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

2 REPLIES 2
Anonymous
Not applicable

Hi  @Anonymous,

 

Create a calculated column as below:

 

Batch Number of Campaign = 
var _CFcheck=SEARCH("CF",'Table'[Product],1,BLANK())
Return
IF(_CFcheck=1,0,RANKX(FILTER('Table','Table'[Product]=EARLIER('Table'[Product])),'Table'[Batch],,ASC,Dense))

 

Finally you will see:

Annotation 2020-06-17 105635.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

@Anonymous , create a sub-category type of rank on Date or Shift , that should work

refer For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

 

Check for Category Rank and Sub Category Rank

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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
Top Kudoed Authors