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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Cumulative counting based only on the earliest date per ID

Hello,

 

I am currently working with a data set to produce cumulative counts (which I have working perfectly) however I have a problem with my next step.

 

The data should all at some point go through "Stage 1" however due to various reasons it doesn't always happen.

 

My data looks like this:

 

IDStageDate Entering Stage
ABC1Stage 101/01/2010
ABC2Stage 202/01/2010
ABC3Stage 112/01/2010
ABC1Stage 207/01/2010
ABC1Stage 309/01/2010
ABC2Rejected10/01/2010
ABC3Stage 319/01/2010


I have produced cumulative lines based on Stage 1, Stage 2, Stage 3 and Rejected and have them working. What I need is another cumulative line of the earliest date the ID appeared. A first recorded in the system line.  

 

 

So for ABC1 this would be 01/01/2010 in Stage 1 as it should be.

But ABC2 doesn't have a Stage 1 so I need to assume the Stage 1 date was the first date in the system (02/01/2010 Stage 2)

 

My first thought was to add rows for every ID missing Stage 1 using the earliest date found for that ID but I cant figure out how to do it? Or is there a way to produce a cumulative count filtered by only the first appearance of the ID?

 

DAX or PowerQuery solutions would be fine... Unfortunately there's no way to change the source data.

 

Thank you,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous,


For your scenario, I have two ideas to deal with this, perhaps you can refer to below formulas.

 

1. Use min date of whole table as the first date of loss 'stage 1' records.

FirstDate = 
var lookup=LOOKUPVALUE('Sample'[Date Entering Stage],'Sample'[ID],[ID],'Sample'[Stage],"Stage 1")
return
IF(ISBLANK(lookup),FIRSTDATE(ALL('Sample'[Date Entering Stage])),lookup)

2. Use exist min date of current record as the first date.

FirstDate2 = MINX(FILTER(ALL('Sample'),[ID]=EARLIER('Sample'[ID])),[Date Entering Stage])

 

Result:

8.PNG

 

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous,


For your scenario, I have two ideas to deal with this, perhaps you can refer to below formulas.

 

1. Use min date of whole table as the first date of loss 'stage 1' records.

FirstDate = 
var lookup=LOOKUPVALUE('Sample'[Date Entering Stage],'Sample'[ID],[ID],'Sample'[Stage],"Stage 1")
return
IF(ISBLANK(lookup),FIRSTDATE(ALL('Sample'[Date Entering Stage])),lookup)

2. Use exist min date of current record as the first date.

FirstDate2 = MINX(FILTER(ALL('Sample'),[ID]=EARLIER('Sample'[ID])),[Date Entering Stage])

 

Result:

8.PNG

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Number 2 did exactly as I needed. Thank you.

CahabaData
Memorable Member
Memorable Member

I have a solution that I'm hesitant to post because it is such a kludge - also I come from the database world and think in terms of a sequence of sql queries that would perform this.  At a high level this is what must be done (if one is in a database world).

a. list of unique IDs

b. list of IDs with Stage 1 (only)

c. outer join (b) list to (a) list - - and where there are nulls in the a list in the Stage column - these are the one's you need to deal with

d. insert a value where is null

e. append to original table

 

I could set this up relatively quickly if I were using database technology, although it is still difficult to explain - however to implement this with the Query Editor in PBI is going to be a bunch of steps - and since there is no double joins allowed one is going to need to create a merge field of ID & Stage in order to accomplish the outer join.....

 

Hopefully someone better than I at DAX will see this and suggest a more sane solution......

www.CahabaData.com

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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