Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - General Discussion
Answered

IF statement error

(0) ShareShare
ReportReport
Posted on by 53

Hello

 

I need to convert months to their respective quarters, any idea why the below does not work?

 

if(int(formatDateTime(utcNow(),'M'))<4,'Q1',if(int(formatDateTime(utcNow(),'M'))<7,'Q2',if(int(formatDateTime(utcNow(),'M'))<10,'Q3','Q4')))

 

Thanks!

  • joelzehring Profile Picture
    208 on at
    Re: IF statement error

    I don't think that will work in your use case.

     

    ExpressionEvaluated
    utcNow('M')April 27
    utcNow('MM')04

     

    More info: Standard date and time format strings | Microsoft Docs

  • PowerAutomate3 Profile Picture
    53 on at
    Re: IF statement error

     

    @joelzehring  I think the problem is that I used 'M' instead of 'MM'. I really wanted to use e.g. 1 for January and not 01. Isn't it possible? Why it results in an error?

     

  • joelzehring Profile Picture
    208 on at
    Re: IF statement error

    I'm not able to reproduce that error... Can you share a screenshot of where you're using this line of code and any modifications you may have made?

  • PowerAutomate3 Profile Picture
    53 on at
    Re: IF statement error

    Thanks but I get the error:

     

    The template language function 'int' was invoked with a parameter that is not valid

     

    Any ideas?

  • joelzehring Profile Picture
    208 on at
    Re: IF statement error

    Nested "if" expressions can be a pain, so I took a slightly different approach. The below expression is just returning the quarter number, which can be concatenated with a "Q" later:

    if(greater(mod(int(utcNow('MM')),3),0), add(div(int(utcNow('MM')),3),1), div(int(utcNow('MM')),3))

     

  • Verified answer
    Expiscornovus Profile Picture
    32,131 Most Valuable Professional on at
    Re: IF statement error

    Hi @PowerAutomate3,

     

    Instead of the < character you could use the less function in your expression.

     

    You can also simplify the expression a bit. You can remove the formatDateTime functions. Try the expression below.

    if(less(int(utcNow('MM')), 4), 'Q1', if(less(int(utcNow('MM')), 7), 'Q2', if(less(int(utcNow('MM')),10), 'Q3', 'Q4')))

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1