web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : lPZJqAyci4KFxuY4JlTer8
Power Automate - General Discussion
Answered

IF statement error

Like (0) ShareShare
ReportReport
Posted on 7 Apr 2022 10:54:05 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!

I have the same question (0)
  • joelzehring Profile Picture
    208 on 27 Apr 2022 at 15:42:31
    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 27 Apr 2022 at 15:15:35
    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 07 Apr 2022 at 23:45:03
    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 07 Apr 2022 at 23:34:47
    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 07 Apr 2022 at 18:29:39
    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,292 Most Valuable Professional on 07 Apr 2022 at 14:36:07
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 783 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 515 Moderator

#3
trice602 Profile Picture

trice602 299 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading complete