Confusing Multiple IF statements with AND

%3CLINGO-SUB%20id%3D%22lingo-sub-2036944%22%20slang%3D%22en-US%22%3EConfusing%20Multiple%20IF%20statements%20with%20AND%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2036944%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20-%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI%20am%20trying%20to%20create%20a%20macros%20that%20will%20do%20the%20following%20%3A%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EColumn%20F%20(Duration)%20%3D%20calculates%20the%20days%20between%20First%20engaged%20(D)%20and%20Last%20Check%20columns%20(E).%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EColumn%20G%20(Agreement%20Time)%20This%20is%20the%20complex%20one%20%3D%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EIf%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EImportance%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EHIGH%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESite%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDA109%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EService%20Owner%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPainters%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDuration%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3D%26lt%3B3%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ETHEN%20%22%3CSTRONG%3EWITHIN%20AGREEMENT%3C%2FSTRONG%3E%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EOR%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EIf%20the%20Importance%20is%20Medium%20AND%20Site%20is%20DA109%20AND%20Service%20Owner%20is%20Painters%20AND%20Duration%20is%20%3D%26lt%3B3%20days%20THEN%20%22NOT%20WITHIN%20AGREEMENT%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EOR%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EIf%20the%20Importance%20is%20low%20AND%20Site%20is%20DA109%20AND%20Service%20Owner%20is%20Painters%20AND%20Duration%20is%20%3D%26lt%3B3%20days%20THEN%20%22cancel%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EOR%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EIf%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EImportance%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EHIGH%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESite%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDMT1944%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EService%20Owner%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPainters%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EAND%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDuration%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3D%26lt%3B3%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ETHEN%20%22%3CSTRONG%3ENOT%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EWITHIN%20AGREEMENT%3C%2FSTRONG%3E%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3Edepending%20on%20the%20site%2C%20importance%20and%20service%20owner%20combination%2C%20it%20will%20tell%20me%20if%20im%20within%20agreement%20or%20not.%26nbsp%3B%20%26nbsp%3BI%20am%20attaching%20the%20main%20spreadsheet%20im%20working%20on%2C%20sheet%20one%20is%20the%20main%20sheet%2C%20sheet%20two%20is%20the%20logic%20for%20the%20formula%2C%20the%20thing%20is%20each%20cell%20will%20have%20the%20entire%20IF%2FAND%2FOR%20formula.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2036944%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Etraining%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2037757%22%20slang%3D%22en-US%22%3ERe%3A%20Confusing%20Multiple%20IF%20statements%20with%20AND%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2037757%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F920075%22%20target%3D%22_blank%22%3E%40RickJames_%3C%2FA%3E%26nbsp%3BI%20could%20write%20a%20long%20nested%20IF%2FIFS%20statement%20but%20there%20are%20a%20few%20issues.%26nbsp%3B%20First%20is%20that%20your%20logic%20doesn't%20make%20sense%20or%20isn't%20complete.%26nbsp%3B%20You%20have%20%22LOGIC%22%20sheet%20that%20only%20addresses%20Gardners%20and%20in%20the%20above%20post%20you%20address%20Painters%20and%20then%20above%20you%20have%20%26lt%3B%3D3%20days%20for%20every%20case%20and%20the%20result%20changes%20based%20on%20the%20Importance%20(I%20doubt%20that%20was%20your%20intent)%20and%20then%20on%20the%20sheet%20you%20have%20the%20cases%20that%20are%20%26gt%3B%3D%20some%20days%20as%20sometime%20NOT%20within%20agreement%20but%20other%20times%20they%20ARE%20within%20agreement%20(which%20I%20suppose%20is%20possible)%20but%20the%20alternative%20in%20each%20case%20is%20%3D%20(EQUALS)%20some%20duration%20instead%20of%20%26lt%3B%20the%20other%20value%20which%20is%20even%20more%20an%20issue%20when%20the%20%3D%20value%20is%20%26gt%3B%3D%20the%20other%20value%20and%20hence%20BOTH%20conditions%20could%20be%20true%20and%20many%20cases%20where%20neither%20condition%20is%20true.%3C%2FP%3E%3CP%3E%26nbsp%3B%20That%20all%20said%2C%20it%20feels%20like%20you%20have%20an%20explicit%20duration%20threshold%20for%20each%20combination%20and%20it%20would%20be%20easier%20to%20just%20add%20a%20column%20called%20Contract%20Duration%20and%20enter%20it%20there%20(assuming%20you%20clear%20up%20those%20discrepancies).%26nbsp%3B%20If%20this%20is%20just%20a%20small%20sampling%20and%20you%20actually%20have%20hundreds%20or%20thousands%20of%20these%20and%20lots%20of%20each%20combination%20then%20I%20would%20recommend%20trying%20to%20create%20a%20lookup%20table%20(similar%20to%20what%20you%20have%20on%20the%20LOGIC%20page)%20so%20that%20based%20on%20site%2C%20owner%2C%20and%20importance%20the%20formula%20can%20find%20the%20Critical%20Duration%20value%20(assuming%20the%20things%20I%20noted%20above%20are%20just%20errors%20and%20can%20be%20cleared%20up).%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello -

I am trying to create a macros that will do the following :

 

Column F (Duration) = calculates the days between First engaged (D) and Last Check columns (E).

Column G (Agreement Time) This is the complex one =

If the Importance is HIGH AND Site is DA109 AND Service Owner is Painters AND Duration is =<3 THEN "WITHIN AGREEMENT"

OR

If the Importance is Medium AND Site is DA109 AND Service Owner is Painters AND Duration is =<3 days THEN "NOT WITHIN AGREEMENT"

OR

If the Importance is low AND Site is DA109 AND Service Owner is Painters AND Duration is =<3 days THEN "cancel"

OR

If the Importance is HIGH AND Site is DMT1944 AND Service Owner is Painters AND Duration is =<3 THEN "NOT WITHIN AGREEMENT"

 

depending on the site, importance and service owner combination, it will tell me if im within agreement or not.   I am attaching the main spreadsheet im working on, sheet one is the main sheet, sheet two is the logic for the formula, the thing is each cell will have the entire IF/AND/OR formula. 

 

1 Reply

@RickJames_ I could write a long nested IF/IFS statement but there are a few issues.  First is that your logic doesn't make sense or isn't complete.  You have "LOGIC" sheet that only addresses Gardners and in the above post you address Painters and then above you have <=3 days for every case and the result changes based on the Importance (I doubt that was your intent) and then on the sheet you have the cases that are >= some days as sometime NOT within agreement but other times they ARE within agreement (which I suppose is possible) but the alternative in each case is = (EQUALS) some duration instead of < the other value which is even more an issue when the = value is >= the other value and hence BOTH conditions could be true and many cases where neither condition is true.

  That all said, it feels like you have an explicit duration threshold for each combination and it would be easier to just add a column called Contract Duration and enter it there (assuming you clear up those discrepancies).  If this is just a small sampling and you actually have hundreds or thousands of these and lots of each combination then I would recommend trying to create a lookup table (similar to what you have on the LOGIC page) so that based on site, owner, and importance the formula can find the Critical Duration value (assuming the things I noted above are just errors and can be cleared up). 

  In the attached I changed you LOGIC page to make a table like I described and added a corresponding formula to do a lookup and check the duration accordingly.  Note I also created a formula to automatically take that text you have for date-time and convert them into dates and find the difference in days.