Excel: Complex Lookup + 'If Cell Contains' - excel-formula

Example of sheet 1
Where I have repeated entries for the employee. Most employees will have two different shift types but some might have one. The profile contains days of the week and each day of the week is unique to one profile (i.e. no overlapping days between profiles).
employee_name / shift_type / profile
mr_a / type_a / Saturday_Sunday
mr_a / type_b / Monday_Tuesday_Wednesday
mr_a / type_b / Thursday_Friday
mrs_b / type_a / Sunday_Monday_Tuesday
mrs_b / type_b / Wednesday_Thursday_Friday
Example of sheet 2
Where I have a log of each employee, the shift type and the specific day of the week.
employee_name / shift_type / day_of_week
mr_a / type_a / Saturday
mr_a / type_b / Wednesday
mr_a / type_b / Friday
Desired Results:
What I would like to do is successfully match the records from sheet 2 against sheet 1. I want to do is match the profile where:- match employee_name and shift_type are on an 'exact' basis and the profile returned matches the day_of_the_week on a non-exact basis (only a partial match based on the part of the string)
Like so:
employee_name / shift_type / day_of_week / matching_profile
mr_a / type_a / Saturday / Saturday_Sunday
mr_a / type_b / Wednesday / Monday_Tuesday_Wednesday
mr_a / type_b / Friday / Thursday_Friday
What I have tried:
I have tried using array formulae and have been able to solve both halves of the problem. I can get the multiple-matching conditions using multiple lookup criteria in an index_match. However, I don't know how to then combine that to find the match where the cell contains part of the text (i.e. the weekday).
Something like this (but which isn't working):
=INDEX('sheet1'!profile,MATCH(1, (employee_name='sheet1'!A:A) * (shift_type*'sheet1'!B:B) * (TRUE,ISNUMBER(SEARCH(day_of_week,'sheet1'!profile),0))
Thank you for any help!

Try this one, it's an array formula, so enter with CNTRL + SHIFT + ENTER:
{=OFFSET(Sheet1!$C$1,(MATCH(1,--(Sheet1!A:A=Sheet2!A3)*(Sheet1!B:B=Sheet2!B3)*NOT(ISERROR(SEARCH(Sheet2!C3,Sheet1!C:C))),0))-1,0)}
I'll explain this from the inside out, it makes more sense that way:
(Sheet1!A:A=Sheet2!A3)*(Sheet1!B:B=Sheet2!B3)*NOT(ISERROR(SEARCH(Sheet2!C3,Sheet1!C:C)) is your logical test, it's checking whether B2 is found in Sheet1 B:B and returning 1 where it is and 0 where it isn't. Same thing with A2 and A:A. NOT(ISERROR(SEARCH(Sheet2!C2,Sheet1!C:C))) is checking each cell in C:C to see if it contains a partial match of the text in C2. This returns an array of 0's and 1's.
MATCH(1,(array from above),0) tells you where in the array the first 1 occurs. It returns a single number.
OFFSET(Sheet1!$C$1,(Number from above)-1,0) takes the value from Sheet1, column C, and uses the number from above to find the row.
This formula will return the "Weekday_Weekday_Weekday" in column C if there is a match, and #N/A if there is not. If C2 is left blank it will return the "Weekday_Weekday_Weekday" anyways (error only occurs if weekday doesn't match).

Here is a solution I was able to leverage using Wildcards. As a caveat for anybody using this, be mindful that this is basically doing partial matches. However, given that the employee_name and shift_type in my example are unique identifiers, this didn't bother me. This would be an issue for anybody who is matching values which might be sub-strings.
=INDEX(sheet_1!C:C,MATCH("*"&sheet_1!A2&"*"&"*"&Sheet1!B2&"*"&"*"&Sheet1!C2&"*",sheet_1!B:B&sheet_1!D:D&sheet_1!C:C,0))

Related

How can I extract a total count or sum of agents who made their first sale in a specified month?

I am trying to extract some data out of a large table of data in Excel. The table consists of the month, the agent's name, and either a 1 if they made a sale or a 0 if they did not.
What I would like to do is plug in a Month value into one cell, then have it spit out a count of how many agents made their first sale that month.
Sample Data and Input Output area
I found success by creating a secondary table for processing a minif and matching to agent name, then countif in that table's data how many sales months matched the input month. However I would like to not have a secondary table and do this all in one go.
=IF(MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1)=0,"No Sales",MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1))
=COUNTIFS(ProcessedData[Month of First E2E Sale],H4)
Formula in column F is:
=MAX(0;COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1)-SUM(COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;IF($A$2:$A$8=E3;$B$2:$B$8))))
This is how it works (we'll use 01/03/2022 as example)
COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1) This counts how many 1 there are for the proper month (in our example this part will return 2)
COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;SI($A$2:$A$8=E3;$B$2:$B$8)) will count how many 1 you got in previous months of the same agents (in our example, it will return 1)
Result from step 2, because it's an array formula, we sum up using SUM() (in our example, this return 1)
We do result from step 1 minus result from step 3 (so we get 1)
Finally, everything is inside a MAX function to avoid negative results (February would return -1 because there were no sales at all and agent B did a sale on January, so it would return -1. To avoid this, we force Excel to show biggest value between 0 and our calculation)
NOTE: Because it's an array formula, depending on your Excel version maybe you must introduce pressing CTRL+ENTER+SHIFT
If one has got access to the newest functions:
=LET(X,UNIQUE(C3:C9),VSTACK({"Month","Total of First time sales"},HSTACK(X,BYROW(X,LAMBDA(a,SUM((C3:C9=a)*(MINIFS(C3:C9,D3:D9,D3:D9,E3:E9,1)=C3:C9)))))))

How can I search and extract in between slash in Excel formula?

I have a list of rows in excel as below.
Australia Order / 111233 -12213AUS / AUD900 / Ready to dispatched
UnitedKingdom Order / 187633 -123413UK / USD 800 / goods
1133 -1013AUS/Australia Order / AUD450 / Ready to dispatched
Australia Order /AUD900 / Ready to dispatched / 1873 -1726A
How can I search "-" and extract the value into a new column? Some of the "-' number are not in sequence after the slash.
Expected result:
111233 -12213AUS
187633 -123413UK
1133 -1013AUS
1873 -1726A
There is quite a bit of string manipulation involved, but I guess you can try this:
=TRIM(MID(LEFT(A2,IFERROR(FIND("/",A2,FIND("-",A2))-1,LEN(A2))),IFERROR(FIND("#",SUBSTITUTE(A2,"/","#",LEN(LEFT(A2,IFERROR(FIND("/",A2,FIND("-",A2))-1,LEN(A2))))-LEN(SUBSTITUTE(LEFT(A2,IFERROR(FIND("/",A2,FIND("-",A2))-1,LEN(A2))),"/",""))))+1,1),LEN(A2)))
The formula basically locates the position of the - and gets the position of the previous and next / relative to that of the -.
Alternatively you could use text to columns and use a lookup with a wildcard:
This will work in your case:
=TRIM(RIGHT(SUBSTITUTE(LEFT(A1,FIND("/",A1&"/",FIND("-",A1))-1),"/",REPT(" ",99)),99))
Find index "/" after "-" in string -> extract text from begin to this index
Get last word from this string
Hope it helps!

Using Advanced Lookup Functions in Excel

So, I have this workbook consisting of Summary:Temperatures by Month.
There are two worksheets with Summary - High Temp and Summary - Low Temp.
The Summary High Temp Worksheet looks like this:
City/State/Jan/Feb/Mar/Apr
{[ColB]/[ColC]/[ColD]/[ColE]/[ColF]/[ColG]}
R5: A/AA/30/32/40/42
R6: B/BB/32/34/41/43
R7: C/CC/38/36/44/45
R8: D/DD/40/39/47/49
Now, I have to retrieve data for "CITY-WIDE HIGH TEMPERATURES BY MONTH" from Summary High Temp Worksheet into another worksheet that is currently in this format:
City/High Temp
{[ColJ]/[ColI]}
R5:A/ _________
R6:B/ _________
R7:C/ _________
R8:D/ _________
Moreover, I have drop-down list with Month Names and Month Numbers like these:
Month:Mar
[Cell:B3/C3]
Month Number: 3
[Cell:J2/K2]
[The drop-downs are dynamic in nature. So for instance, if I select Mar in Month it will give me 5 in Month Number etc]
How, can I make use of the above list in my formula to retrieve temperatures for the specified city and month?
the are 2 easy ways to do this
1) make a cheat column that is city+month combined so you have a unike identifier so in a new column you could reefer to firhst the month locked in line 1 and then the city in different lines (=$B$1&C2 and then drag down)
2) since you only have one unike value pr city/mont/high or low you could do a "MAXIFS" where you specify city + month as criteria
You don't need an INDEX-MATCH to accomplish this, it can be done by utilizing HLOOKUP-MATCH to retrieve a value at an intersection point. I recreated a basic layout of your data and in J5 used
=HLOOKUP($B$3,'Summary - High Temp '!$B$4:$G$8,MATCH(I5,'Summary - High Temp '!$B$4:$B$8,0),FALSE)
Where $B$3 is a reference to your drop down list of month names, 'Summary - High Temp '!$B$4:$G$8 is reference to your high temp data array, I5 is a reference to the City being searched for and 'Summary - High Temp '!$B$4:$B$8 is a reference to the column containing the array of city names.
This would allow you to select any month from your drop down list and your search values would update. This, of course, assumes you only have one temperature value for each unique City-Month.

Determine number of days (not including weekend) based on hours given

I have two important details that are inputted into an excel table, Job_Start_Date and Job_Hours (meaning the hours required to complete the job). Given certain working hours (eg 7:00am-3:30pm) I need to calculate what day and what time they will finish. I already have that basic bit working, but I cannot for the life of me figure out how to skip weekends in that calculation (Note that there is a boolean for Sat/Sun that defines whether that day should be skipped).
Here is an example of the data
and an example of the data visualization: (The DIV errors are because employee count equals 0, pay this no mind.)
.
This is the formula used in the visualizer (a massive index match)
=IFNA(INDEX(INDIRECT(Allocation!$A$1), MATCH(1,($A3 = INDIRECT(Allocation!$K$1))
* (C$1 >= INDIRECT(Allocation!$C$1)) * (C$1 <= INDIRECT(Allocation!$D$1))
* IF(C$1 = INDIRECT(Allocation!$C$1), ($B3 >= INDIRECT(Allocation!$E$1)),
($B3 >= INDIRECT(Allocation!$I$1))) * IF(C$1 = INDIRECT(Allocation!$D$1),
($B3 < INDIRECT(Allocation!$F$1)), ($B3 < INDIRECT(Allocation!$J$1))), 0)),"")
As you can see in the image, Saturdays need to be skipped (being FALSE), but it is still shown on the visualizer. However, if I include a statement that matches the Saturday condition (so it only shows up on a Saturday if TRUE), it will not alter the end date and thus will not push the final day to Monday.
Essentially the question is: How can I skip days but preserve the 'working hours'. This must be done in excel formulas in the same Job table (first image).
Thanks.
Here is how I got it working using WORKDAY.INTL.
First is a nested IF to determine which weekend type to use for the workday.intl function
Weekend=IF(OR([#[JOB SATURDAY]], [#[JOB SUNDAY]]), IF(AND([#[JOB SATURDAY]], [#[JOB SUNDAY]]), -1, IF([#[JOB SATURDAY]], 11, 17)), 1)
Then a second if statement that references that value and then spits out the correct date
=IF([#[Weekend]] = -1, [#[JOB START DATE]]+[#[Working Days]], WORKDAY.INTL([#[JOB START DATE]], [#[Working Days]], [#[Weekend]]))

Line graph from date ranges with multiple people

I have a list of tasks in Excel. After each task there is a start date, end date, and # people required to complete the task.
How do I make a line graph that shows how many people we need on any given day, based on the information provided?
(For some reason, this site won't allow me to upload a table or image, but my data is below)
Task / Start Date / End Date / # People
A / 5-11-15 / 5-15-15 / 1
B / 5-14-14 / 5-25-15 / 3
C / 5-15-15 / 5-20-15 / 2
D / 5-18-15 / 5-22-15 / 1
E / 5-20-15 / 5-27-15 / 2
I found a previous post that is similar, but it only uses the COUNTIFS formula - I believe I need to multiply then count. See Line graph from date ranges
In the screenshot below, the formula in cell G2 (pasted into the entire range G2:K18) is
=SUMIFS($D$2:$D$6,$B$2:$B$6,"<="&$F2,$C$2:$C$6,">="&$F2,$A$2:$A$6,"="&G$1)
L2 is simply =SUM(G2:K2)
I would make a stacked column chart using F1:K18.

Resources