Forum

Notifications
Clear all

Count no. of days between two dates on a row but reduce if criteria meets and immediate row above has the the same second date as the first date of the second row

10 Posts
3 Users
0 Reactions
117 Views
(@learner)
Posts: 5
Active Member
Topic starter
 

Hi, I created a query, but Excel is not accepting it. Can you please help with what could be done to fix it?

=if(or(IF(AND(I9="Yes",I8="No"),DATEDIF(B9,C9,"d"),"NA"),if(and(i9="yes",i8="yes",B9=C8),DATEDIF(B9,C9,"d")-1,"NA")))

 
Posted : 03/12/2021 11:59 am
(@jstewart)
Posts: 216
Estimable Member
 

Hi Jayendra!

Your OR(IF) statements already have what to do if the statements are false. Either nix the first IF statement and have the formula read

=OR(IF(AND(I9="Yes",I8="No"),DATEDIF(B9,C9,"d"),"NA"),if(and(i9="yes",i8="yes",B9=C8),DATEDIF(B9,C9,"d")-1,"NA")).

or re-write it so that if neither of the OR statements are true the result would read NA

=if(or(IF(AND(I9="Yes",I8="No"),DATEDIF(B9,C9,"d")),if(and(i9="yes",i8="yes",B9=C8),DATEDIF(B9,C9,"d")-1)),,"NA").

If your looking for a TRUE/FALSE answer 86 the "NA" altogether. Not exactly sure what your desired result is so I hope one of these solutions gets you started on your solution.

 
Posted : 03/12/2021 2:25 pm
(@learner)
Posts: 5
Active Member
Topic starter
 

Many thanks, Jessica. The first formula you suggested says True and the second NA. I am still not getting the desired number of days required. Following is the table for which I need result on the last column (Additional Allowance days). The purpose is to avoid counting one day more if a person is moving from one applicable 'Additional Allowance Station' to another (you see, the departure date of Place C and the arrival date of D are the same, and both fall under additional allowance station; so to avoid double counting 25/08/21. Thank you in advance for your support

Place ARRIVAL DATE DEPARTURE DATE Additional Allowance Station Additional Allowance days
A 07/08/21 07/08/21  No                    -  
B 07/08/21 24/08/21  No   FALSE
C 24/08/21 25/08/21  Yes   NA 
D 25/08/21 10/10/21  Yes   NA 
 
Posted : 04/12/2021 2:56 am
(@jstewart)
Posts: 216
Estimable Member
 

Can you please provide a sample worksheet with an example of the desired results. That way I'm not trying to recreate your spreadsheet.

 
Posted : 04/12/2021 11:54 am
Anders Sehlstedt
(@sehlsan)
Posts: 971
Prominent Member
 

Hello,

You can use following formula to get what you want.

=IF(AND(I8=I9,I9="Yes",B9=C8),(C9-B9)-1,
IF(AND(I8=I9;I9="No"),NA(),C9-B9))

Br,
Anders

 
Posted : 04/12/2021 3:40 pm
(@learner)
Posts: 5
Active Member
Topic starter
 

Here, attached. Thanks.

 
Posted : 04/12/2021 3:53 pm
(@learner)
Posts: 5
Active Member
Topic starter
 

Hi Anders,

Somehow it didn't work. Is it possible to do on the spreadsheet I shared?

Many thanks.

Jay

 
Posted : 04/12/2021 4:01 pm
Anders Sehlstedt
(@sehlsan)
Posts: 971
Prominent Member
 

Hello,

See attached, if this is not the result you want then please give an example. I used the same formula as provided earlier.

Br,
Anders

 
Posted : 04/12/2021 6:08 pm
(@learner)
Posts: 5
Active Member
Topic starter
 

Thanks a lot, Anders. It worked. I further added few more criteria so the result is as desired. I've attached the file here.

Best regards,
Jayendra

 
Posted : 06/12/2021 3:40 pm
Anders Sehlstedt
(@sehlsan)
Posts: 971
Prominent Member
 

Hello,

Sorry, no file attached. If you’re having problem with getting correct results using AND / OR logic then perhaps this article can give you some help.

Br,
Anders

 
Posted : 07/12/2021 1:46 am
Share: