• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

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|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / 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|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Count no. of days between two dates…
sp_PrintTopic sp_TopicIcon
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
Avatar
Jayendra Koirala

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
December 3, 2021
sp_UserOfflineSmall Offline
1
December 3, 2021 - 1:59 am
sp_Permalink sp_Print

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")))

Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 205
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
2
December 3, 2021 - 4:25 am
sp_Permalink sp_Print

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.

Avatar
Jayendra Koirala

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
December 3, 2021
sp_UserOfflineSmall Offline
3
December 3, 2021 - 4:56 pm
sp_Permalink sp_Print

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 
Avatar
Jessica Stewart
Northern USA
Member
Members


Trusted Members
Level 0
Forum Posts: 205
Member Since:
February 13, 2021
sp_UserOfflineSmall Offline
4
December 4, 2021 - 1:54 am
sp_Permalink sp_Print

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

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 871
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
5
December 4, 2021 - 5:40 am
sp_Permalink sp_Print

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

Avatar
Jayendra Koirala

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
December 3, 2021
sp_UserOfflineSmall Offline
6
December 4, 2021 - 5:53 am
sp_Permalink sp_Print

Here, attached. Thanks.

Avatar
Jayendra Koirala

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
December 3, 2021
sp_UserOfflineSmall Offline
7
December 4, 2021 - 6:01 am
sp_Permalink sp_Print

Hi Anders,

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

Many thanks.

Jay

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 871
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
8
December 4, 2021 - 8:08 am
sp_Permalink sp_Print

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

Avatar
Jayendra Koirala

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
December 3, 2021
sp_UserOfflineSmall Offline
9
December 6, 2021 - 5:40 am
sp_Permalink sp_Print

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

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 871
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
10
December 6, 2021 - 3:46 pm
sp_Permalink sp_Print

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

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: SALLY, Valentyn Kristioglo, Tiffany Kang
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Bruce Tang Nian
Scot C
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Forum Stats:
Groups: 3
Forums: 24
Topics: 6223
Posts: 27294

 

Member Stats:
Guest Posters: 49
Members: 31919
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.