+ Reply to Thread
Results 1 to 14 of 14

Nested if function issue

  1. #1
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Nested if function issue

    Hi,

    I've created this nested IF function with & "...." property to get the exact no of years, no of months & no of days from a particular date.

    But here i am unable to figure out to adjust singular & plurals, like Month & Months or Day or Days.

    Could any one please help me to put the if nest properly to set the above requirement.

    VCare

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Nested if function issue

    I think this will work for you...
    =IF(A2="","",IF(B2=A2,"DOB",IF(DATEDIF(A2,B2,"y")=0,IF(DATEDIF(A2,B2,"m")=0,DATEDIF(A2,B2,"d")&" Day"&IF(DATEDIF(A2,B2,"d")>1,"s",""),DATEDIF(A2,B2,"m")&" Month"&IF(DATEDIF(A2,B2,"m")>1,"s","")),DATEDIF(A2,B2,"y"))))
    where A2 is the date and B2 is today(), so substitute as necessary.

    EDIT: and if you want it with today in it already...
    =IF(A1="","",IF(TODAY()=A1,"DOB",IF(DATEDIF(A1,TODAY(),"y")=0,IF(DATEDIF(A1,TODAY(),"m")=0,DATEDIF(A1,TODAY(),"d")&" Day"&IF(DATEDIF(A1,TODAY(),"d")>1,"s",""),DATEDIF(A1,TODAY(),"m")&" Month"&IF(DATEDIF(A1,TODAY(),"m")>1,"s","")),DATEDIF(A1,TODAY(),"y"))))
    Last edited by Sam Capricci; 06-21-2018 at 08:18 AM.
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  3. #3
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Nested if function issue

    if you really want to its a bit of a pain to do I would do separate ifs

    if(a1>today(),"",ROUNDDOWN((TODAY()-A1)/365.25,0)&if(ROUNDDOWN((TODAY()-A1)/365.25>1," years, ","year, ")...........

    and continue similarly for the months and days

  4. #4
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Re: Nested if function issue

    Hi,

    I'm actually not using excel 2010 or excel 2013. DATEDIF is not available in my excel.

  5. #5
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Nested if function issue

    It works from way back. I use 2016 and it works without problem and it has worked since I started using it in the 98 version.
    It just doesn't show up in the list but datedif does work. Give it a try to see.

  6. #6
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Re: Nested if function issue

    I tried with your formula, but still it gives value in difference of Years only, if i split this for month it shows total number of months between two dates.
    If is use the exact formula you provided it is giving me the value as "2" & nothing else.

  7. #7
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Nested if function issue

    Ok, I think this works out the year/years issue, give it a try and let me know...
    =IF(A2="","",IF(TODAY()=A2,"today",IF(DATEDIF(A2,TODAY(),"y")=0,IF(DATEDIF(A2,TODAY(),"m")=0,DATEDIF(A2,TODAY(),"d")&" Day"&IF(DATEDIF(A2,TODAY(),"d")>1,"s",""),DATEDIF(A2,TODAY(),"m")&" Month"&IF(DATEDIF(A2,TODAY(),"m")>1,"s","")),IF(DATEDIF(A2,TODAY(),"y")=1,DATEDIF(A2,TODAY(),"y")&" year",DATEDIF(A2,TODAY(),"y")&" years"))))

  8. #8
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Nested if function issue

    Vcare

    The question has to be asked, why does your profile say excel 2010? It hinders people answering your question as they can wast time creating solutions that don't work if you don't have it?.I agree with sambo kid that it should work with earlier versions.

    It has been available since 2000 https://exceljet.net/excel-functions...tedif-function

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: Nested if function issue

    Vcare - please update your user profile to reflect the version of Excel being used. Thanks!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Re: Nested if function issue

    Hi,
    Excuse me, i was working in other system for while...

  11. #11
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Re: Nested if function issue

    Hi Sambo Kid,
    thank you for your help.
    I tried the formula exactly you gave... It's giving me the result as "4 years" if my date in cell A2 is 22-Feb-2014.

  12. #12
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Nested if function issue

    Ok, I think I see what you are wanting now, see if this will work for you...
    =IF(DATEDIF(A2,TODAY(),"y")>1,DATEDIF(A2,TODAY(),"y")&" years, ",DATEDIF(A2,TODAY(),"y")&" year, ")&IF(DATEDIF(A2,TODAY(),"ym")>1,DATEDIF(A2,TODAY(),"ym")&" months, ",DATEDIF(A2,TODAY(),"ym")&" month, ")&IF(DATEDIF(A2,TODAY(),"md")>1,DATEDIF(A2,TODAY(),"md")&" days",DATEDIF(A2,TODAY(),"md")&" day")

    let me know.

  13. #13
    Registered User
    Join Date
    11-29-2016
    Location
    India
    MS-Off Ver
    2010 2007
    Posts
    59

    Re: Nested if function issue

    Thank you Sambo Kid... that exactly worked... I worked out the same in very lengthy formula i guess... because of this i my excel performance was slow.

    =IF(A1>TODAY(),"",CONCATENATE(IF(ROUNDDOWN((TODAY()-A1)/365.25,0)=1,ROUNDDOWN((TODAY()-A1)/365.25,0)&" Year ",ROUNDDOWN((TODAY()-A1)/365.25,0)&" Years "))&IF(ROUNDDOWN(((TODAY()-A1)/365.25-ROUNDDOWN((TODAY()-A1)/365.25,0))*12,0)=1,ROUNDDOWN(((TODAY()-A1)/365.25-ROUNDDOWN((TODAY()-A1)/365.25,0))*12,0)&" Month ",ROUNDDOWN(((TODAY()-A1)/365.25-ROUNDDOWN((TODAY()-A1)/365.25,0))*12,0)&" Months ")&IF(DAY(A1)>DAY(TODAY()),DAY(EOMONTH(TODAY(),-1))-DAY(A1)+DAY(TODAY())&" Days ",(IF(IF(DAY(A1)<=DAY(TODAY()),DAY(EOMONTH(A1,0))-DAY(A1)+1-DAY(EOMONTH(TODAY(),0)-DAY(TODAY())),"")=1,IF(DAY(A1)<=DAY(TODAY()),DAY(EOMONTH(A1,0))-DAY(A1)+1-DAY(EOMONTH(TODAY(),0)-DAY(TODAY())),"")&" Day ",IF(DAY(A1)<=DAY(TODAY()),DAY(EOMONTH(A1,0))-DAY(A1)+1-DAY(EOMONTH(TODAY(),0)-DAY(TODAY())),"")&" Days"))))

  14. #14
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.84 for Mac MS 365
    Posts
    8,499

    Re: Nested if function issue

    Glad I was able to help. Please don't forget to mark the post as solved using the thread tools dropdown at the top of the post. And if you are so inclined "* Add Reputation" is always appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Nested vlookup or nested IFAND function?
    By jeptik in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-11-2017, 02:27 AM
  2. [SOLVED] Nested if functions issue
    By kobiashi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-11-2016, 09:49 AM
  3. Nested if function issue
    By agdavis93 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-30-2016, 03:21 PM
  4. Issue with nested Or statement
    By MikeSta4ord in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-23-2015, 12:48 PM
  5. [SOLVED] Issue with nested IF function and structured references
    By jason1983 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-28-2015, 08:13 PM
  6. [SOLVED] Nested IF Statement Issue
    By mbhc77 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2013, 03:46 PM
  7. Issue with too many nested IF statements
    By sjak in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-05-2008, 03:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1