Index function with a conditional range

Gedeon

New Member
Joined
Jun 18, 2014
Messages
2
Hello,

Here is the spreadsheet I have: (simplified)
This is saying which shift corresponds to which staff every day.

DayShiftStaff 1Staff 2Staff 3
Monday10:00x
Monday15:00xx
Monday20:00
Tuesday10:00xx
Tuesday15:00
Tuesday20:00x

<tbody>
</tbody>


And here is the output I would want to get:


DayFunctionShift
MondayStaff 1
MondayStaff 2
MondayStaff 3
TuesdayStaff 1
TuesdayStaff 2
TuesdayStaff 3

<tbody>
</tbody>


I am looking here for the shift corresponding to each staff on each day. I would like to have only one formula for the whole table as the database is quite big.

I have tried with an INDEX MATCH function and I was able to get the shift for each staff but I couldn't get the "day" variable with it. I would like to do: INDEX(Shift column ONLY for Monday; MATCH("x";INDEX(The whole table;0;MATCH("Staff 1"; Column headers;0);0);0)
But I do not know how to do the "Shift column ONLY for Monday" range.

Do you know any way to do this?

Thank you very much for your help!

Gedeon
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi Gedeon and Welcome to MrExcel,

Let's assume you define a named ranges to make it easier to reference parts of your table:

Name: tblSchedule RefersTo: A1:E22 (your entire table)
Name: lstDays RefersTo: =INDEX(tblSchedule,0,1) (your first column)
Name: lstShifts RefersTo: =INDEX(tblSchedule,0,2) (your second column)
Name: hdrSchedule RefersTo: =INDEX(tblSchedule,1,0) (your first row)

Finding the first instance for a given day of the week is pretty straight-forward using =MATCH(thisday, lstDays,0)
You can find the last instance of a day using an array formula, or helper cells. An alternative would be to have your list of days in ascending order
so you can use =MATCH(thisday, lstDays,1) to efficiently find the last instance of a given day.

Obviously you don't want to sort the day strings alphabetically (Friday, Monday, Saturday....Tuesday). :)
but you could:
Number the days ("1. Monday", "2. Tuesday".....)
Use serial dates then use the custom number format "dddd" to display 1/1/2001 as "Monday", 1/2/2001 as "Tuesday".....

If you use this second tactic you'll need to use the corresponding serial dates in your second table.
Using this second tactic and the defined names listed above, here's one formula that would work....

In J2, then copied down:
Code:
=INDEX(INDEX(tblSchedule,MATCH($H2,lstDays,0),0):
    INDEX(tblSchedule,MATCH($H2,lstDays,1),0) lstShifts,
        MATCH("x",INDEX(tblSchedule,MATCH($H2,lstDays,0),0):
            INDEX(tblSchedule,MATCH($H2,lstDays,1),0) INDEX(tblSchedule,0,
                MATCH(I2,hdrSchedule,0))))
Excel Workbook
HIJ
1DayFunctionShift
2MondayStaff 115:00
3MondayStaff 210:00
4MondayStaff 315:00
5TuesdayStaff 120:00
6TuesdayStaff 210:00
7TuesdayStaff 310:00
Sheet


There's probably simpler formulas, but this could give you a starting point.
 
Last edited:
Upvote 0
Hello Jerry,

Thank you very much for your reply!
It is exactly what I was looking and answers the question perfectly.

Using the index(...):index(...) to define the range I was looking for was the key. To find the last occurence of the day, I alternatively added a countif(thisday) to the second match of the index range, and using dates works perfectly, since a date a unique (vs. a day of the week which comes back every week).

My problem is solved, thank you Jerry!

Gedeon
 
Upvote 0

Forum statistics

Threads
1,216,129
Messages
6,129,055
Members
449,484
Latest member
khairianr

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