take and sort if

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
hi all - how can I expand on Fluff's formula to include to return the same ranges only if column E contains the text "shift 1"?

=TAKE(SORT(HSTACK(i43:i1501,d43:d1501),1,-1),5)

so still looks at top 5 times in column I
matches the times to the reason code in column D

but only gets the top 5 times for the text "shift 1" from column E


TIA
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
In that case, I would probably create the desired arrays using CHOOSECOLS with FILTER, rather than HSTACK:
MrExcel_20240131_C (version 1).xlsx
DEFGHI
37md50.abc
38kc
39jb
40i49.xyzd49.abc
41i44.xyzd44.abc
42
43d43.abcshift 2i43.xyz
44d44.abcshift 1i44.xyz
45d45.abcshift 1g
46ashift 2h
47bshift 1j
48cshift 1k
49d49.abcshift 1i49.xyz
50d50.abcshift 1m
51
Sheet4
Cell Formulas
RangeFormula
F37:G41F37=TAKE(SORT(CHOOSECOLS(FILTER(D43:I1501,E43:E1501="shift 1"),6,1),1,-1),5)
Dynamic array formulas.
 
Upvote 0
I should have offered another variant. The one posted previously filters a larger array to remove undesired rows first, then chooses the columns to keep in the correct order. The second version is closer to the idea presented by @Fluff where the columns are first stacked together in the correct order, and then they are filtered to remove the undesired rows.
MrExcel_20240131_C (version 1).xlsx
DEFGHI
37md50.abcmd50.abc
38kckc
39jbjb
40i49.xyzd49.abci49.xyzd49.abc
41i44.xyzd44.abci44.xyzd44.abc
42
43d43.abcshift 2i43.xyz
44d44.abcshift 1i44.xyz
45d45.abcshift 1g
46ashift 2h
47bshift 1j
48cshift 1k
49d49.abcshift 1i49.xyz
50d50.abcshift 1m
Sheet4
Cell Formulas
RangeFormula
E37:F41E37=TAKE(SORT(CHOOSECOLS(FILTER(D43:I1501,E43:E1501="shift 1"),6,1),1,-1),5)
H37:I41H37=TAKE(SORT(FILTER(HSTACK(I43:I1501,D43:D1501),E43:E1501="shift 1"),1,-1),5)
Dynamic array formulas.
 
Upvote 0
In that case, I would probably create the desired arrays using CHOOSECOLS with FILTER, rather than HSTACK:
MrExcel_20240131_C (version 1).xlsx
DEFGHI
37md50.abc
38kc
39jb
40i49.xyzd49.abc
41i44.xyzd44.abc
42
43d43.abcshift 2i43.xyz
44d44.abcshift 1i44.xyz
45d45.abcshift 1g
46ashift 2h
47bshift 1j
48cshift 1k
49d49.abcshift 1i49.xyz
50d50.abcshift 1m
51
Sheet4
Cell Formulas
RangeFormula
F37:G41F37=TAKE(SORT(CHOOSECOLS(FILTER(D43:I1501,E43:E1501="shift 1"),6,1),1,-1),5)
Dynamic array formulas.
thanks KRice this worked.

however.... and I suspect I can't... but need to add criteria to this.

How can i return the same results but also include if Column B = BOSCH
 
Upvote 0
How can i return the same results but also include if Column B = BOSCH
Can you clarify this? My example shows data in columns D:I, with a condition on column E having "shift 1". Are you saying that some other column in the range of D:I might or might not have the word "BOSCH"...or are you expanding the range of source data from column A or B to I? And then you only want results that are both "shift 1" AND "BOSCH"?...or do you want results that are either "shift 1" OR "BOSCH"?
 
Upvote 0
Can you clarify this? My example shows data in columns D:I, with a condition on column E having "shift 1". Are you saying that some other column in the range of D:I might or might not have the word "BOSCH"...or are you expanding the range of source data from column A or B to I? And then you only want results that are both "shift 1" AND "BOSCH"?...or do you want results that are either "shift 1" OR "BOSCH"?
That's correct.

I tried expanding the range even to column A, but had no luck

the column containing Bosch is in B... so adding another criteria where it looks at both columns B and E

Hope this image helps
 

Attachments

  • Screenshot 2024-02-05 103305.png
    Screenshot 2024-02-05 103305.png
    13.3 KB · Views: 2
Upvote 0
okay…and is the condition AND (both must be met) or OR (either condition may be met)?
 
Upvote 0
Thanks...the AND condition (both criteria must be met) is readily achieved by multiplying the two conditional arrays together:
MrExcel_20240131_C (version 1).xlsx
BCDEFGHI
37jbjb
38i49.xyzd49.abci49.xyzd49.abc
39gd45.abcgd45.abc
40
41
42
43BOSCHd43.abcshift 2i43.xyz
44d44.abcshift 1i44.xyz
45BOSCHd45.abcshift 1g
46BOSCHashift 2h
47BOSCHbshift 1j
48cshift 1k
49BOSCHd49.abcshift 1i49.xyz
50d50.abcshift 1m
51
Sheet4
Cell Formulas
RangeFormula
E37:F39E37=TAKE(SORT(CHOOSECOLS(FILTER(D43:I1501,(B43:B1501="BOSCH")*(E43:E1501="shift 1")),6,1),1,-1),5)
H37:I39H37=TAKE(SORT(FILTER(HSTACK(I43:I1501,D43:D1501),(B43:B1501="BOSCH")*(E43:E1501="shift 1")),1,-1),5)
Dynamic array formulas.
 
Upvote 0
Solution
Thanks...the AND condition (both criteria must be met) is readily achieved by multiplying the two conditional arrays together:
MrExcel_20240131_C (version 1).xlsx
BCDEFGHI
37jbjb
38i49.xyzd49.abci49.xyzd49.abc
39gd45.abcgd45.abc
40
41
42
43BOSCHd43.abcshift 2i43.xyz
44d44.abcshift 1i44.xyz
45BOSCHd45.abcshift 1g
46BOSCHashift 2h
47BOSCHbshift 1j
48cshift 1k
49BOSCHd49.abcshift 1i49.xyz
50d50.abcshift 1m
51
Sheet4
Cell Formulas
RangeFormula
E37:F39E37=TAKE(SORT(CHOOSECOLS(FILTER(D43:I1501,(B43:B1501="BOSCH")*(E43:E1501="shift 1")),6,1),1,-1),5)
H37:I39H37=TAKE(SORT(FILTER(HSTACK(I43:I1501,D43:D1501),(B43:B1501="BOSCH")*(E43:E1501="shift 1")),1,-1),5)
Dynamic array formulas.
Hi KRice - the result for me still returns VALUE... i used the HSTACK formula. the ranges paste just fine, but no value returned
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,269
Members
449,093
Latest member
Vincent Khandagale

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