+ Reply to Thread
Results 1 to 12 of 12

IF formula To Convert Months To Quarters

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    IF formula To Convert Months To Quarters

    I created the following formula to convert a field with months (G:G) to what quarter of the year it falls in.

    Formula: copy to clipboard
    =IF(G2={"Jan","Feb","Mar"},1,IF(G2={"Apr","May","Jun"},2,IF(G2={"Jul","Aug","Sep"},3,4)))


    It doesn't work, how do I get it to work?



    *Edit/Correction: I should probably check to see if the formula works in all the cells I want it to first.
    Last edited by Craig K.; 05-23-2013 at 05:04 PM.

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF formula To Convert Months To Quarters

    If G2 contains the month name as a TEXT entry...

    =CEILING(MONTH(1&G2)/3,1)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: IF formula To Convert Months To Quarters

    with VLookup in a table.

    put the months in column A and the quarter i column B

    =Vlookup(g2,sheet2!a1:b12,2,0)
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  4. #4
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: IF formula To Convert Months To Quarters

    This is my take... but it might be longer...

    =ROUNDUP(MATCH(B5083,{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)/3,0)

  5. #5
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: IF formula To Convert Months To Quarters

    Tony, I just reverse engineered it and that formula is beautiful. I hate using formulas I don't understand.

    Thank You!

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF formula To Convert Months To Quarters

    Quote Originally Posted by Craig K. View Post
    Tony, I just reverse engineered it and that formula is beautiful. I hate using formulas I don't understand.

    Thank You!
    Me too!

    I do the same thing when I see something different. I "slice it and dice it" until I get it then I test it under all kinds of scenarios to see how it reacts.

    This is how we learn.

    Thanks for the feedback!

  7. #7
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: IF formula To Convert Months To Quarters

    Tony, nice trick with 1&G2... how did you know this can be read in as a date?

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: IF formula To Convert Months To Quarters

    I have many years of experience with Excel and I do tons of experimentation trying different things.

    There must be something wrong with me because I love this stuff!

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: IF formula To Convert Months To Quarters

    I'd go with Tony's suggestion but just in the interests of learning......

    Your original formula will work OK with ORs, i.e.

    =IF(OR(G2={"Jan","Feb","Mar"}),1,IF(OR(G2={"Apr","May","Jun"}),2,IF(OR(G2={"Jul","Aug","Sep"}),3,4)))
    Audere est facere

  10. #10
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: IF formula To Convert Months To Quarters

    Longlegs - could you explain to me why the OR function makes it work?

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,699

    Re: IF formula To Convert Months To Quarters

    For an IF function to work as required the "test" should normally give you a single TRUE/FALSE answer but when you use G2={"Jan","Feb","Mar"} that returns an "array" of TRUE/FALSE values, e.g. if G2 = "Feb" you get {FALSE,TRUE,FALSE}. In your formula you want TRUE if any of those is TRUE so that's an OR, either of these will give you a single TRUE/FALSE

    =OR(G2={"Jan","Feb","Mar"})

    or

    =OR(G2="Jan",G2="Feb",G2="Mar")

  12. #12
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: IF formula To Convert Months To Quarters

    I'm still trying to understand arrays and thought the way I had it written (without the OR()) would allow it to cycle through. Thanks for the lesson!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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