Excel Formula to find and place Unique Value, calculate days between the first entry and last entry

%3CLINGO-SUB%20id%3D%22lingo-sub-1850269%22%20slang%3D%22en-US%22%3EExcel%20Formula%20to%20find%20and%20place%20Unique%20Value%2C%20calculate%20days%20between%20the%20first%20entry%20and%20last%20entry%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850269%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EIn%20the%20table%20below%20I%20require%20to%20find%20formula%20to%20fill%20out%20column%20C%20and%20D%2C%20since%20I%20have%20thousand%20of%20records%20to%20filter%20through%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ECOLUMN%20A%20has%20duplicate%20ID%20which%20I%20need%20to%20identify%20the%20distinct%20ID%20in%20COLUMN%20D%20as%20shown%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ENumber%20of%20days%20for%20each%20distinct%20ID%20from%20start%20to%20finish%20which%20is%20in%20Step%20Date%20(column%20B)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Eexample%3A%2010000523052%20is%20from%204%2F30%2F2020%20-%207%2F27%2F2020%20%3D%2088%20days%3B%20For%20every%20Unique%20ID%2C%20Days(Last%20Entry%20date%20-%20First%20Entry%20Date)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EI%20want%20this%20identified%20for%20each%20ID%20in%20column%20D%20as%20shown.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EWhat%20should%20be%20the%20formula%20for%20Column%20D%20and%20Column%20C%20to%20show%20Unique%20ID%20and%20days%20between%20first%20entry%20and%20last%20entry%20for%20the%20specific%20ID%20at%20the%20top%20entry%3F%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%20class%3D%22cms_table%22%3E%3CTABLE%20width%3D%22500%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3EA%3C%2FTD%3E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3CTD%3E10000523088%3C%2FTD%3E%3CTD%3E7%2F28%2F2020%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E10000523088%3C%2FTD%3E%3CTD%3E7%2F15%2F2020%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E10000523088%3C%2FTD%3E%3CTD%3E4%2F30%2F2020%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E10000523088%3C%2FTD%3E%3CTD%3E4%2F30%2F2020%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThanks%20for%20your%20help%20in%20advance.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1850269%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1850581%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Formula%20to%20find%20and%20place%20Unique%20Value%2C%20calculate%20days%20between%20the%20first%20entry%20and%20last%20en%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850581%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F856295%22%20target%3D%22_blank%22%3E%40bxsilva1740%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20a%20more%20elegant%20solution%2C%20in%20that%20it%20will%20list%20all%20the%20Unique%20IDs%20all%20bunched%20together...you%20could%20even%20put%20these%20formulas%20on%20their%20own%20page%2C%20apart%20from%20the%20database%20itself.%3C%2FP%3E%3CP%3EThe%20use%20of%20%3CSTRONG%3EUNIQUE%3C%2FSTRONG%3E%20does%20require%20the%20most%20recent%20edition%20of%20Excel.%20If%20you%20have%20that%20edition%2C%20you%20will%20find%20this%20preferable%20to%20the%20prior%20solution.%3C%2FP%3E%3CP%3EPut%20this%20wherever%20you%20want%20it.%20I%20illustrate%20it%20in%20Column%20C%2C%20but%20it%20could%20be%20placed%20elsewhere.%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DUNIQUE(A3%3AA11)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EUNIQUE%3C%2FSTRONG%3E%20will%20%22spill%22%20the%20results%20down%20as%20far%20as%20necessary%20to%20produce%20a%20complete%20list%2C%20so%20there%20should%20be%20no%20other%20content%20below%20it.%3C%2FEM%3E%3C%2FP%3E%3CP%3EThis%20formula%20remains%20as%20it%20was%20before%2C%20and%20should%20be%20adjacent%20to%20the%20foregoing.%3C%2FP%3E%3CP%3E%3DIF(C3%3D%22%22%2C%22%22%2CMAXIFS(%24B%243%3A%24B%2411%2C%24A%243%3A%24A%2411%2CC3)-MINIFS(%24B%243%3A%24B%2411%2C%24A%243%3A%24A%2411%2CC3))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1850746%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Formula%20to%20find%20and%20place%20Unique%20Value%2C%20calculate%20days%20between%20the%20first%20entry%20and%20last%20en%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850746%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F425987%22%20target%3D%22_blank%22%3E%40mathetes%3C%2FA%3E%26nbsp%3B%20Thanks%20Mathetes.%20the%20suggested%20formula%20did%20not%20work%3B%20the%20result%20of%20the%20formula%20was%200.%3C%2FP%3E%3CP%3EAlso%20looking%20for%20a%20formula%20for%20D3%20to%20compute%20the%20number%20of%20days%20between%20the%20first%20date%20for%20the%20ID%20and%20last%20date%20for%20the%20same%20ID.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1850806%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Formula%20to%20find%20and%20place%20Unique%20Value%2C%20calculate%20days%20between%20the%20first%20entry%20and%20last%20en%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1850806%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F856295%22%20target%3D%22_blank%22%3E%40bxsilva1740%3C%2FA%3E%26nbsp%3BIf%20you%20are%20on%20a%20modern%20version%20of%20excel%2C%20perhaps%20the%20attached%20sheet%20answers%20your%20question.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

In the table below I require to find formula to fill out column C and D, since I have thousand of records to filter through

COLUMN A has duplicate ID which I need to identify the distinct ID in COLUMN D as shown
Number of days for each distinct ID from start to finish which is in Step Date (column B)
example: 10000523052 is from 4/30/2020 - 7/27/2020 = 88 days; For every Unique ID, Days(Last Entry date - First Entry Date)
I want this identified for each ID in column D as shown.

What should be the formula for Column D and Column C to show Unique ID and days between first entry and last entry for the specific ID at the top entry?

ABCD
IDDateDistinct IDDays
100005230527/27/20201000052305288
100005230527/27/2020  
100005230527/27/2020  
100005230524/30/2020  
100005230524/30/2020  
100005230887/28/20201000052308889
100005230887/28/2020  
100005230887/15/2020  
100005230884/30/2020  
100005230884/30/2020  



Thanks for your help in advance.

10 Replies
Highlighted

@bxsilva1740 

 

Here's a method. I'll be curious if other more elegant solutions are proposed.

 

This does presume that you've sorted all of the records by the first column (the ID)... Assuming that's the case, then this formula

=IF(A3<>A2,A3,"")

will populate column C with the new ID each time it changes; otherwise leave it blank.

 

And then, for each row in column C that has a new ID, this formula in column D subtracts the minimum date from the maximum date for the ID in the adjacent column.

=IF(C3="","",MAXIFS($B$3:$B$11,$A$3:$A$11,C3)-MINIFS($B$3:$B$11,$A$3:$A$11,C3))

 

See the attached

Highlighted

@bxsilva1740 

 

Here's a more elegant solution, in that it will list all the Unique IDs all bunched together...you could even put these formulas on their own page, apart from the database itself.

The use of UNIQUE does require the most recent edition of Excel. If you have that edition, you will find this preferable to the prior solution.

Put this wherever you want it. I illustrate it in Column C, but it could be placed elsewhere.

=UNIQUE(A3:A11)

 

UNIQUE will "spill" the results down as far as necessary to produce a complete list, so there should be no other content below it.

This formula remains as it was before, and should be adjacent to the foregoing.

=IF(C3="","",MAXIFS($B$3:$B$11,$A$3:$A$11,C3)-MINIFS($B$3:$B$11,$A$3:$A$11,C3))

 

Highlighted

@mathetes  Thanks Mathetes. the suggested formula did not work; the result of the formula was 0.

Also looking for a formula for D3 to compute the number of days between the first date for the ID and last date for the same ID.

 

Highlighted

@bxsilva1740 If you are on a modern version of excel, perhaps the attached sheet answers your question.

 

Highlighted

@bxsilva1740 

In your file ID are numbers, and Distinc ID are texts first character of which is non-breaking space (unicode 160), most probably they are copy/pasted from Web.

 

For this concrete sample that could be fixed as

=MAXIFS($B$3:$B$11,$A$3:$A$11,SUBSTITUTE(C3,UNICHAR(160),"")*1)-
MINIFS($B$3:$B$11,$A$3:$A$11,SUBSTITUTE(C3,UNICHAR(160),"")*1)
Highlighted

@bxsilva1740

 

I attached spreadsheets in both cases that DID work. I just posted the formula to make the posting more educational.

The second example, using UNIQUE, will not work, as I said, unless you have the newest versions of Excel.

Highlighted
Thanks Riny_van Eekelen; did not work for me. This is what I see. Not supported.

=MAX(_xlfn._xlws.FILTER(B3:B11,(A3:A11=A15)))-MIN(_xlfn._xlws.FILTER(B3:B11,(A3:A11=A15)))

Highlighted

@bxsilva1740 

As variant

image.png

C3:
=IFERROR(
  INDEX($A$3:$A$11,
        AGGREGATE(15,6,1/(COUNTIF($A$3:A3,A3)=1)*(ROW()-ROW($A$2)),1)
  ),
"")

D3:
=IFERROR(
  AGGREGATE(14,6,1/(COUNTIFS(C3,$A$3:$A$11))*$B$3:$B$11,1)-
  AGGREGATE(15,6,1/(COUNTIFS(C3,$A$3:$A$11))*$B$3:$B$11,1),
"")

and drag down

Highlighted
Highlighted