Excel "Nested IF" of multiple columns and multiple conditions per row - excel

I have a problem that seems so simple, but I can't wrap my head around it. I have a large database, and i have two separate columns that unfortunately need to stay that way, which together are defining the time of an incident: Column A consists of an integer number "1" to "12", and Column B consists of cells with either "PM" or "AM". I need a separate column that gives me a "1" for anything that happened between 8 AM and 4 PM and a "0" for all else. Part of the problem obviously are the "12" "PM" rows. That's all I have so far:
=IF(AND(A1>=8, A1<=11),IF(B1="AM",1,0),0)
, which puts out correctly a "1", if anything happened between 8 AM and 11 AM, but not the rest. I need to combine it with:
=IF(AND(A1>=1, A1<=4),IF(B1="PM",1,0),0)
and:
=IF(AND(A1=12),IF(B1="PM",1,0),0)
but I have no idea how to combine all of these in one statement at the same time. Can anybody help?

This was a fun exercise - I'm sure there's a dozen ways to do it but here's what I found:
=IF(AND(TIME(IF(B1="PM",A1+12,A1),0,0)>=TIME(8,0,0),TIME(IF(B1="PM",A1+12,A1),0,0)<=TIME(11,0,0)),1,0)
Goes in C1
So my approach was --
If B1 is PM, then give me A1 + 12 (hours), otherwise just give me A1
IF(B1="PM",A1+12,A1)
Return a time value equal to that many hours
TIME(IF(B1="PM",A1+12,A1),0,0)
Check and see if it's greater than a value of exactly 8 hours...
TIME(IF(B1="PM",A1+12,A1),0,0)>=TIME(8,0,0)
Then wrap it in an And statement with an identical function asking if it's less than 11.
I don't like that it repeats itself, and that I have to use TIME(8,0,0) to return a value of 8 hours.. Maybe you or someone else can offer improvements or other suggestions.

Or you can try this:
=IF(AND(TIMEVALUE(A1&" "&B1)>=(8/24),TIMEVALUE(A1&" "&B1)<=(16/24)),1,0)
Simple and direct. You just need to convert what you have to its equivalent time value(between 0-1 in Excel).
And then just evaluate it using AND operand with 8/24(8AM) and 16/24(4PM). HTH.
Result:

Related

EXCEL - Filtering rows by multiple OR conditions

I have this problem I'm trying to solve in EXCEL, hopefully it's a straightforward one somebody can help with.
Essentially I Have 6 columns, which can be of values 'compliant' or 'missing'.
What I'd like to achieve is that in the 7th column, 'compliant' or 'non-compliant' is written, if the following conditions are met:
1 of column N,L,J is missing (i.e. max of 2 'missing')
Or any of P,V,Z is missing (i.e. none can be 'missing')
I hope that makes sense. At the minute I've cobbled together this horrible formula, but I think I'm on the wrong track completely:
=IF(OR(N2="Missing",L2="Missing",J2="Missing"),"Non-compliant",""),IF(OR(P2="Missing",V2="Missing",Z2="Missing"),"Non-compliant","")
I think the logic you have is close but I don’t think an if statement can check if less than two cells are equal to something. My approach would be to sum a few Boolean values by converting true to 1 and false to 0 with the INT function. So:
=if(or(sum(int(N2=“missing”),int(L2=“Missing),int(J2=“missing))>1,sum(int(P2=“missing”),int(V2=“missing”),int(Z2=“missing”))>0),”non-compliant”,””)
Hope this helps!
=IF(AND(COUNTIF(J1:N1,"m")>1,OR(P1="m",V1="m",Z1="m")),"non-compliant","compliant")

nested if calculation in excel

I have column I as a calulation column and this is what I currently wrote.
and this gives me nothing.
=IF(B2<>""&D2<>"",B2*D2,IF(B2<>""&D2=""&C2<>"",B2*C2,IF(A2<>""&C2<>""&AND(B2&D2=""),A2*C2,IF(A2<>""&C2=""&D2<>""&B2="",A2*D2,A2*C2))))
The logic is if B2 and D2 are not null multiply b2*d2
if B2 is not null and D2 null then b2*c2
If B2 is null and D2 is not null then a2*d2
else a2*c2
Is any ways to make this code work?
Thank you
Alternative ways or rewriting your formula:
=IF(AND(B2<>"",D2<>""),B2*D2,IF(D2="",IF(B2<>"",B2*C2,A2*C2),IF(D2<>"",A2*D2,A2*C2)))
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2="",D2=""),A2*C2,IF(D2="",B2*C2,A2*D2)))
They will make negligible difference in performance and what not. BruceWayne's answer is probably more readable in terms of following your logic and therefore easier to maintain or understand in the future. The above answers should provide the same results but are a few characters shorter in length.
And as a wacky alternative for thinking potentially outside the box:
=CHOOSE(SUM((B2<>"")*2+(D2<>""))+1,A2*C2,A2*D2,B2*C2,B2*D2)
Expanding (not just my waist size)
I had time on my hands so I was fooling around with the concept of TRUE and FALSE being equal to 1 and 0 when sent through a math operation. When I started looking at the options this reminded me of how a binary number works. Not that I have bgiven it too much thought, but I think it works because the options for each cell are binary or TRUE/FALSE. Since every possible combination was covered with a unique out come, I just had to come up with a formula that would produce unique results. In this case I just took the converting a a binary number approach. The key is TRUE = 1 after a math operation and FALSE = 0. Now going the other direction is not quite the same but as Jeeped once put it, 0 is FALSE and everything else is TRUE. so 3, -3, and 3.14 are all treated as TRUE if using the numerical values as the outcome of a logic check.
=IF(3.14,"THIS NUMBER IS TRUE","ONLY 0 IS FALSE")
So less side tracking and back on point (not sure how much I need to expand to!).
Looking at the table above, you will note in the yellow area, all possible combination for BLANK and NOT BLANK are listed. If you then assign a value to the column the same way binary numbers are (note row A) you can then start generating all the possible numbers
I started by generating the list I needed in E2:E5 for numbers that CHOOSE could work with. I assumed 0 would beat up CHOOSE and cause it to fail. I knew that FALSE+FALSE=0 and I also knew that TRUE+TRUE=2 and that both TRUE+FALSE=1 and FALSE+TRUE=1. I needed a way to distinguish the later two and I knew I needed a total of 4 results. That is when binary counting/conversion whatever you want to call it kicked in. I placed the following formula in D2 and copied down
=SUM((A2<>"")*2+(B2<>""))
Note the brackets around the logic check and
that the logic checks are sent through a math
operation before being summed.
technically speacking it is really:
=SUM((A2<>"")*2+(B2<>"")*1)
however the *1 is not needed
once I had that list generate, it was a simple +1 added to it to get into the 1 to 4 range seen in E2:E5.
Now that I had a way of generating the index number the only thing left to do was to match up the required results/formula with the right combination.
=CHOOSE(SUM((A2<>"")*2+(B2<>""))+1,"A","B","C","D")
Well I felt like I was beating a dead horse there for a bit, so if I over explained, my apologies. If there is something still missing ask for more explination.
UPDATE TID BIT
IF there were more columns to check it may be possible to adjust the choose formula by simply adding the next binary value to the column and making sure there is an appropriate number of results in the choose list. There should be 2^(# of columns to check) options
=CHOOSE(SUM((A2<>"")*4+(A2<>"")*2+(B2<>""))+1,"A","B","C","D","E","F","G","H")
Which kind of beats multiple nested IFs for brevity, but I think I finds the nested IFs easier to understand.
You should be using AND():
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2<>"",D2=""),B2*C2,IF(AND(B2="",D2<>""),A2*D2,A2*C2)))
You seem to be mixing operators from other programming languages:
In Excel:
AND : binary operator : AND(TRUE, FALSE) => FALSE
& : concatenation : "Hello " & "World" => "Hello World"

excel CountIf or

Both options work fine as you can see in my picture of my spreadsheet in column R & Q where the counts are.
Most of my columns are in military time formats like 24:00 one of the column I am working on is the X column that I am trying to get added to this time count if possible I a Number column where the numbers start from 10,11,13 and so on. Long story short.
I need Numbers in column X # 10 ,11 to be in the count for count for column O as you can see in column Q & R I got it set up for my count and it works just fine but that’s without the special deal I need from column X where I only needs these numbers from 10,11, a few from # 13.
So, in a nut shell I just need it to say give me the column O times if there is a # 10,11,13 in column X
= COUNTIF($O$13:$O$1000,">=0:21")-COUNTIF($O$13:$O$1000,">0:30")
Connection time
Connection time
https://support.google.com/docs/answer/3093480 - similar functionality. You have 0:21 - 0:30.. What's that all about? Zeros? O21 or 0.21? etc. If it's meant to be time, you want to strip out that stuff, and add things up probably using decimals so 30 seconds is 0.5 min.. Or convert everything to seconds... Then you can convert back after.If it's minutes and you want the granularity split it into columns. LEFT(cell,FIND(":"),cell) , RIGHT(cell,len(cell)-find(":")). May be off by one either way so a +1,-1 may be needed... Then convert text to number VALUE(text). And countif does not allow strings for comparison. So quotes around last parameter are a "no no"! Only numbers..
Instead of
=COUNTIF($O$13:$O$1000,">=0:21")-COUNTIF($O$13:$O$1000,">0:30")
Try the following:
=COUNTIF($O$13:$O$1000,">="&Time(0,21,0))-COUNTIF($O$13:$O$1000,">"&time(0,30,0))

Excel Formula overly complex

I have a formula that builds a string with If statements, CONCATENATE, and text formulas.
My problem is that the formula's getting extremely larger than I ever wanted it.
My formula first looks to see if a cell if blank
=IF(I3="","",Else)
The Second part is to check if the letters "DKB" is in the H cell
=IF(ISNUMBER(SEARCH("*DKB*",$H3)),True,False)
The Third is if the duration (Cell F) has 0 hrs do not include (HH)
=IF(TEXT(F3,"HH")<>"00",CONCATENATE(TEXT(F3,"hh\h\r mm\m\i\n"),CONCATENATE(TEXT(F3,"mm\m\i\n"))
The Fourth one is if the are 0 min don't include min selection
=IF(TEXT(F3,"MM")<>"00",CONCATENATE(Text(F3,"HH:MM")),CONCATENATE(Text(F3,"HH"))
If I were to write all the ways this could get played out I would have a total of 10 IF's. I want a simple way to write for each option without having to write out each answer. I have a partial code but doesn't include the minute portion. Is there a better way to do this? as you can see me using only if statements I'm not an expert.
Here's a picture to demonstrate my sample data and sample output
If we could have a variable for the first part ie:10-17 to 9:10 PM
2nd variable for duration
3rd variable for DKB
Would this be possible
Perhaps something like this is what you're looking for:
=IF(I3="","",TEXT(A3,"mm-dd-yyyy")&" On-Site "&TEXT(E3,"hh:mm AM/PM")& "- "&TEXT(G3,"hh:mm AM/PM")&" "&TEXT(F3,"hh\h\r mm\m\i\n")&IF(COUNTIF(H3,"*DKB*"),MID(H3,4,20),""))
=IF(I3="","",TEXT(A3,"mm-dd-yyyy")&" On-Site "&TEXT(E3,"hh:mm AM/PM")&"- "&TEXT(G3,"hh:mm AM/PM")&" "&IF(COUNTIF(F3,"*:00:*"),TEXT(F3,"hh\h\r"),IF(COUNTIF(F3,"00:*:*"),TEXT(F3,"mm\m\i\n"),TEXT(F3,"hh\h\r mm\m\i\n"))&IF(COUNTIF(H3,"*DKB*"),MID(H3,4,20),""))))
This Will Make is so It won't show 00hr or 00min

Excel - How to combine these formulas into one?

I have this worksheet which lists results oldest to newest dates.
I have these three formulas..
=IFERROR(LARGE(IF([#HomeTeam]=[HomeTeam],IF("H"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF("A"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
=IF(AND([#[SLWD_H1]]="NULL",[#[SLWD_H2]]="NULL"),"NULL",MAX(Results[#[SLWD_H1]:[SLWD_H2]]))
Basically the first looks for the last time the home team won a game at home.
The second looks for the last time the home team won a game away from home.
And then the third gives me the latest date of the two mentioned above.
I was wondering if there was a way to combine all three into a single column instead of having to have three?
Thankyou in advance.
**EDIT
To make myself a bit clearer! What I want is to combine the above 3 into one formula which will output the result!
So it will find the date in example 1 and find the date in example 2 and then it will output the latest date.
Use the MAX formula to determine the highest date between the home and away dates.
The formula would look like this:
=MAX(Number1,Number2)
The MAX formula will ignore the NULL text values. However if both values are NULL, it will return a zero value. If formatted as a date it will show as 00/01/1900
=MAX(IFERROR(LARGE(IF([#HomeTeam]=[HomeTeam],IF("H"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL"),IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF("A"=[FTR],IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL"))
If I understand correctly, would an OR("A"=[FTR],"H"=[FTR]) work? This would work like your first formula except using both "A" and "H" games.
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF(OR("A"=[FTR],"H"=[FTR]),IF([Date]<[#Date],IF([#Season]=[Season],[Date],"")))),1),"NULL")
Are these the only two values for [FTR]? If so you could just get rid of that IF statement entirely requiring either H or A:
=IFERROR(LARGE(IF([#HomeTeam]=[AwayTeam],IF([Date]<[#Date],IF([#Season]=[Season],[Date],""))),1),"NULL")

Resources