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
chris_k
Helper I
Helper I

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
v-shex-msft
Community Support
Community Support

Hi @chris_k,


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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @chris_k,


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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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