Forum Discussion

RJF61's avatar
RJF61
Copper Contributor
Oct 26, 2023

Calculated Column with Dates and "IF"

I've been working on this for a bit and just can't find the correct syntax.

 

if(([Created] > 6/30/21 and [Created] <7/1/2022), "2022", if(([Created] > 6/30/22 and [Created] <7/1/2023), "2023", "2024"))

 

Can someone assist?

  • Tristan999's avatar
    Tristan999
    Iron Contributor

    RJF61 You need to add the error you are receiving. I do get the gist of what you are trying to do so here is an example:

     

    In SharePoint, you can use calculated columns to display data based on other columns in your list or library. To achieve your goal, you can create a calculated column with a formula that checks the "Created" field and returns the string "2022" or "2023"  or "2024" based on the specified date ranges. Here's how you can do it:

    1. Go to your SharePoint list or library.
    2. Click on "Settings" (gear icon) and then select "List settings" or "Library settings" depending on what you have.
    3. Under the Columns section, click on "Create column."
    4. Give your column a name, like "Fiscal Year"
    5. For the type of information in this column, choose "Calculated (calculation based on other columns)."
    6. In the "Formula" box, enter the following formula:

     

    =IF(AND(Created>DATE(2021,6,30),Created<DATE(2022,7,1)),"2022",IF(AND(Created>DATE(2022,6,30),Created<=DATE(2023,7,1)),"2023","2024"))

     

    This formula checks if the "Created" date falls within the specified ranges and returns the appropriate string.

    7. For "The data type returned from this formula is:", select "Single line of text."
    8. Click "OK" to save the column.

     

    Now, when items are added to your list or library, this new column will automatically display "2022" or "2023" based on when the item was created. If the creation date does not fall within the specified ranges, the column will be empty.

     

    Please like and mark as best response if you found this helpful 🙂

  • Tristan999's avatar
    Tristan999
    Iron Contributor

    RJF61 Please include the error when you post.

     

    I do get the gist of what you are trying to do. 

     

    Here is a starter sample of what you were trying to do:

     

    =IF(AND(Created>DATE(2021,6,30),Created<DATE(2022,7,1)),"2022",IF(AND(Created>DATE(2022,6,30),Created<DATE(2023,7,1)),"2023",""))

     

    Please like and mark as best response if this helped you 🙂

    • Chairat_Jin's avatar
      Chairat_Jin
      Copper Contributor
      Thank you so much Teacher.. you helped my life in Sharepoint a lot, I don't have to use power automate... All the best to you and family. 🙂
  • RJF61 Use calculated column formula like below: 

     

     

    =IF(AND([Created] > DATE(2021,6,30), [Created] < DATE(2022,7,1)), "2022", IF(AND([Created] > DATE(2022,6,30), [Created] < DATE(2023,7,1)), "2023", "2024"))

     

     

    Where syntax for DATE function is like: 

     

     

    DATE([Year],[Month],[Day])

     

     

    Note:

    1. Sometimes comma( , ) does not work in formula (it is based on language or regional settings on your site). So in that case use semicolon( ; ) instead of comma( , ).
    2. Use correct display name of your SharePoint columns in above formula.
    3. Wrap column names inside [] if your column name has space in it. For example: [My Column Name].

    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources