Announcements
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!
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')))
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))
Thanks but I get the error:
The template language function 'int' was invoked with a parameter that is not valid
Any ideas?
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?
@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?
I don't think that will work in your use case.
More info: Standard date and time format strings | Microsoft Docs
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.
Congratulations to our 2026 Super Users!
Congratulations to our 2025 community superstars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Haque 552
Valantis 388
11manish 375