Earliest date in row if the text in the adjacent columns matches specific

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
439
Office Version
  1. 365
Platform
  1. Windows
I'm trying to find the earliest date in row across a range of columns if the text in the column immediate left of the matches words in a specific list

I have a table (too large to post here), that contains columns with headings including like these:

"Q1Task", "Q1TaskDate" .... "Q58Task", "Q58TaskDate", with text in the columns ending *Task and dates in those ending *TaskDate,

I can successfully count the number of times specific text from a list in a named range (called "lst_These_Tasks") appears in a given row using
Excel Formula:
=SUM(COUNTIF(Data_Table[@[Q1Task]:[Q58TaskDate],"*"&lst_These_Tasks&"*"))
, and I can find the earliest task date using
Excel Formula:
=MINIFS(Data_Table[@[Q1Task]:[Q58TaskDate],Data_Table[#Headers],[Data_Table[@[Q1Task]:[Q58TaskDate]],"*TaskDate"))
, so I thought combing the two might work, but I'm not getting anywhere. Help would be greatly appreciated!


Book3.xlsx
ABCDEFGHIJKL
1Q1TaskQ1TaskDateQ2TaskQ2TaskDateQ3TaskQ3TaskDateQ4TaskQ4TaskDateEarliest Matching TaskExpected Resultlst_These_Tasks
2This01 Jan 23Other01 Dec 22That02 Feb 2301 Jan 23This
3This02 Nov 22This04 Jul 2202 Nov 22That
4Other09 Dec 22
502 JanOtherOtherThis15 Mar 2315 Mar 23
Sheet1
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about
Excel Formula:
=MIN(MINIFS(Data_Table[@[Q1Task]:[Q58Task],Data_Table[@[Q1TaskDate]:[Q58TaskDate],"*"&lst_These_Tasks&"*"))
 
Upvote 0
How about
Excel Formula:
=MIN(MINIFS(Data_Table[@[Q1Task]:[Q58Task],Data_Table[@[Q1TaskDate]:[Q58TaskDate],"*"&lst_These_Tasks&"*"))
It didn't accept that as a formula.
I changed it to: =MIN(MINIFS(Data_Table[@[Q1Task]:[Q4Task]],Data_Table[@[Q1TaskDate]:[Q4TaskDate]],"*"&lst_These_Tasks&"*")) ...but that gave me just zeros:

Book3.xlsx
ABCDEFGHIJKL
1Q1TaskQ1TaskDateQ2TaskQ2TaskDateQ3TaskQ3TaskDateQ4TaskQ4TaskDateEarliest Matching TaskExpected Resultlst_These_Tasks
2This01 Jan 23Other01 Dec 22That02 Feb 23001 Jan 23This
3This02 Nov 22This04 Jul 22002 Nov 22That
4Other09 Dec 220
502 JanOtherOtherThis15 Mar 23015 Mar 23
Sheet1
Cell Formulas
RangeFormula
I2:I5I2=MIN(MINIFS(Data_Table[@[Q1Task]:[Q4Task]],Data_Table[@[Q1TaskDate]:[Q4TaskDate]],"*"&lst_These_Tasks&"*"))
Named Ranges
NameRefers ToCells
lst_These_Tasks=Sheet1!$L$2:$L$3I2:I5
 
Upvote 0
Are you using 365?
Yes, it looks like what is happening is that the MINFS returns a vertical array of the lowest matched date for each match but includes zero for no matches. AGGREGATE doesn't seem to work instead of MIN because zero isn't an error value...

... so testing
Excel Formula:
=MINIFS(
MINIFS(Data_Table[@[Q1Task]:[Q4Task]],Data_Table[@[Q1TaskDate]:[Q4TaskDate]],"*"&lst_These_Tasks&"*"),
MINIFS(Data_Table[@[Q1Task]:[Q4Task]],Data_Table[@[Q1TaskDate]:[Q4TaskDate]],"*"&lst_These_Tasks&"*")
,">0")

..but that doesn't seem to parse
 
Upvote 0
Ok, how about
Excel Formula:
=LET(m,MINIFS(Data_Table[@[Q1TaskDate]:[Q4TaskDate]],Data_Table[@[Q1Task]:[Q4Task]],lst_These_Tasks),IFERROR(MIN(FILTER(m,m<>0)),""))
 
Upvote 1
Solution
Ok, how about
Excel Formula:
=LET(m,MINIFS(Data_Table[@[Q1TaskDate]:[Q4TaskDate]],Data_Table[@[Q1Task]:[Q4Task]],lst_These_Tasks),IFERROR(MIN(FILTER(m,m<>0)),""))
Fantastic... thank you (even corrects J3 in my example, sorry if that caused confusion!)

So let's see:

The LET sets m to be the array produced by MINIFS(Data_Table[@[Q1TaskDate]:[Q4TaskDate]],Data_Table[@[Q1Task]:[Q4Task]],lst_These_Tasks),
then in (MIN(FILTER(m,m<>0)), FILTER produces and array of the results of m where m doesn't equal 0, and is wrapped with MIN to supply only the smallest. Very smart,

The bit I'm still struggling with is the ranges for the MINIFS function. I don't really understand why the whole range of columns in each of the MINIFS arguments doesn't work but the subsets in the working formula do work - .i.e.

[Q1TaskDate]:[Q4TaskDate] doesn't just have dates (its effectively all columns B:H)
Q1Task]:[Q4Task]] doesn't just have tasks (its effectively all columns A:G)

So why does it work, where [Q1Task]:[Q4TaskDate]] doesn't?
 
Upvote 0
The two ranges are offset by one column, so if any column matches your list the minifs will return the next column
 
Upvote 1

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top