Search, index, filter formula

valmir

Active Member
Joined
Feb 10, 2021
Messages
267
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,
I have this formula:
=IF(ISERROR(SEARCH(","; D2)); D2; INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); COUNTA(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2))) & " - " & INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); 1))
And the data in D2 is:
2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
And the result is:
2007 - 2000
(basically the formula returns the last year followed by dash and the first year)
Now, how can this formula be changed so that I get "2000 - 2007", instead of "2007 - 2000"?
This formula is also returning a single value with no dash if that's the case (as desired)
Thanking you in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Maybe
Excel Formula:
=IF(ISERROR(SEARCH(","; D2)); D2; INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); 1)&" - "&INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); COUNTA(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2))))

But if you just want the 1st & last years from the data in D2 how about
Fluff.xlsm
DE
1
22000, 2001, 2002, 2003, 2004, 2005, 2006, 20072000 - 2007
320102010
Master
Cell Formulas
RangeFormula
E2E2=LET(x,TRIM(TEXTSPLIT(D2,,",")),IF(ROWS(x)=1,x,TEXTJOIN(" - ",,TAKE(x,1),TAKE(x,-1))))
E3E3=LET(x,TRIM(TEXTSPLIT(D3,,",")),IF(ROWS(x)=1,x,TEXTJOIN(" - ",TAKE(x,,1),TAKE(x,-1))))
 
Upvote 0
Solution
Maybe
Excel Formula:
=IF(ISERROR(SEARCH(","; D2)); D2; INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); 1)&" - "&INDEX(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2); COUNTA(FILTER(Seasons!$Q:$Q; Seasons!B:B=Stats!B2))))

But if you just want the 1st & last years from the data in D2 how about
Fluff.xlsm
DE
1
22000, 2001, 2002, 2003, 2004, 2005, 2006, 20072000 - 2007
320102010
Master
Cell Formulas
RangeFormula
E2E2=LET(x,TRIM(TEXTSPLIT(D2,,",")),IF(ROWS(x)=1,x,TEXTJOIN(" - ",,TAKE(x,1),TAKE(x,-1))))
E3E3=LET(x,TRIM(TEXTSPLIT(D3,,",")),IF(ROWS(x)=1,x,TEXTJOIN(" - ",TAKE(x,,1),TAKE(x,-1))))
Thanks a lot! The second option also works perfectly and it's simpler! :biggrin:
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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