Note: This article describes how to check if a date field is in the same quarter as the current quarter. Sometimes, you need to check if a date field is in a later quarter or earlier quarter than the current quarter. To do this you must add in the Year as well. See this article for more info.

Determining whether a date field (like CloseDate) falls in the current quarter seems straightforward, but it can be deceptively tricky. Many admins attempt to solve this with formulas, but common approaches often suffer from inaccuracies, maintenance challenges, or unnecessary complexity.

This blog post will explore:

  1. Common approaches for checking if a date falls in the current quarter.
  2. The pitfalls of these methods.
  3. The best solution: a clean, maintainable formula using the CASE() function.

Why Is This Problem Important?

Salesforce professionals frequently group data by quarters for reports, dashboards, or automation. Reliable quarterly formulas are essential for:

  • Identifying opportunities that need attention in the current quarter.
  • Generating pipeline or revenue forecasts.
  • Validating that dates align with specific timeframes.

Without an inaccurate formula, you risk:

  • Inaccurate data in reports.
  • Misaligned forecasts and KPIs.
  • Broken automations or error-prone validation rules.

Common Approaches and Their Pitfalls

1. Using Direct Comparisons with MONTH()

Example Formula:

OR(
    AND(MONTH(TODAY()) = 1, MONTH(CloseDate) = 1),
    AND(MONTH(TODAY()) = 2, MONTH(CloseDate) IN (1, 2)),
    AND(MONTH(TODAY()) = 3, MONTH(CloseDate) IN (1, 2, 3)),
    ...
)

Why It’s Used:

  • Conceptually straightforward, but a tedious formula and harder to maintain.

Pitfalls:

  1. Complexity and Redundancy:
    • Enumerates every month-to-quarter mapping, making formulas lengthy and repetitive.
  2. Maintenance Nightmare:
    • Adjusting for fiscal year or regional differences requires significant rewrites.
  3. Performance:
    • Evaluating multiple OR and AND conditions slows down execution, especially for large datasets.

2. Using Quarter Number Calculation

Example Formula:

FLOOR((MONTH(CloseDate) - 1) / 3) + 1 = FLOOR((MONTH(TODAY()) - 1) / 3) + 1

Why It’s Used:

  • Compact and avoids redundancy.
  • Relies on basic math to determine quarter numbers.

Pitfalls:

  1. Lack of Readability:
    • The formula is concise but difficult for non-technical users to understand or troubleshoot.
  2. Assumes Calendar Quarters:
    • Does not account for fiscal year variations (e.g., Q1 starting in February).

3. Using the CASE() Function to Map Months to Quarters

Example Formula:

CASE(
    MONTH(TODAY()),
    1, 'Q1',
    2, 'Q1',
    3, 'Q1',
    4, 'Q2',
    5, 'Q2',
    6, 'Q2',
    7, 'Q3',
    8, 'Q3',
    9, 'Q3',
    10, 'Q4',
    11, 'Q4',
    12, 'Q4,
    'NA' /*the default outcome will never happen because TODAY() always has a value*/
) = CASE(
    MONTH(CloseDate),
    1, 'Q1',
    2, 'Q1',
    3, 'Q1',
    4, 'Q2',
    5, 'Q2',
    6, 'Q2',
    7, 'Q3',
    8, 'Q3',
    9, 'Q3',
    10, 'Q4',
    11, 'Q4',
    12, 'Q4,
    'NA' /*the default outcome will never happen when using CloseDate*/
)

Note that if you're referring to a custom date field which is not always populated, then the "else" of 'NA' could happen and that would need to be accounted for. You can do this by nesting the whole formula inside an IF() statement, such as below. This will return False if the CustomDate__c field is NULL, or if Custom_Date__c is not NULL but is not in the same quarter of today.

IF( 
    CustomDate__c != NULL
    &&
    CASE(
        MONTH(TODAY()),
        1, 'Q1',
        2, 'Q1',
        3, 'Q1',
        4, 'Q2',
        5, 'Q2',
        6, 'Q2',
        7, 'Q3',
        8, 'Q3',
        9, 'Q3',
        10, 'Q4',
        11, 'Q4',
        12, 'Q4,
        'NA' /*the default outcome will never happen because TODAY() always has a value*/
    ) 
    = 
    CASE(
        MONTH(Custom_Date__c),
        1, 'Q1',
        2, 'Q1',
        3, 'Q1',
        4, 'Q2',
        5, 'Q2',
        6, 'Q2',
        7, 'Q3',
        8, 'Q3',
        9, 'Q3',
        10, 'Q4',
        11, 'Q4',
        12, 'Q4,
        'NA' /*the default outcome will never happen when using CloseDate*/
    ),
  TRUE,
  FALSE
)

Why This Is Superior:

  1. Readability:
    • Clearly maps months to quarters, making it easy for admins and developers to understand.
  2. Flexibility:
    • Adaptable for fiscal quarters by simply changing the month-to-quarter mappings.
  3. Maintainability:
    • Updates are localized to the CASE() function, avoiding redundant logic or recalculations.
  4. Accuracy:
    • Ensures precise alignment between the current quarter and the date field’s quarter.
  5. Minimal Performance Impact:
    1. The formula evaluates the CASE() function twice (once for TODAY() and once for the date field), making it efficient compared to complex nested OR and AND conditions.

How to Use This Formula

1. Validation Rules

Ensure actions (e.g., updating an opportunity’s stage) only happen when a date is within the current quarter.

Example Validation Rule:

ISPICKVAL( StageName, 'Proposal' ) &&
ExampleField__c = NULL &&
Close_Date_in_Current_Quarter__c = TRUE

This validation rule will only require ExampleField__c at the Proposal stage IF the CloseDate is in the current quarter.


2. Reports and Dashboards

  • Filter an Opportunities report where the Expected Launch Date is in current quarter. Note: could also be modified to show Next quarter instead of current depending on the business use case.

3. Automation

  • Only send an email alert for a won Opportunity if the close date is in the current quarter.

Conclusion

The CASE()-based formula for checking if a date falls in the current quarter is the most efficient, readable, and flexible solution. While other methods may work for basic scenarios, they often lead to complexity, poor performance, and maintenance headaches.

By adopting this clean and reliable formula, Salesforce admins and developers can ensure robust, scalable automations and accurate reporting. If you’re still using outdated approaches, now is the time to switch to this smarter solution.

Tagged in: