Get previous month out of New Dictionary when January

Dear All,

I needed to get the previous quarter, which I found a solution for in this forum.
Solution was this dictionary:

dict = New Dictionary(Of String,String)From{{“Jan”,“Q1”},{“Feb”,“Q1”},{“Mar”,“Q1”},{“Apr”,“Q2”},{“May”,“Q2”},{“Jun”,“Q2”},{“Jul”,“Q3”},{“Aug”,“Q3”},{“Sep”,“Q3”},{“Oct”,“Q4”},{“Nov”,“Q4”},{“Dec”,“Q4”}}

Assign: str_quarter = dict(MonthName(today.month-1,true))

So far so good.

But if the found quarter is Q4 (meaning: today is January, so it should find December which is in Q4), it’s not working.

image

This is the error:
image

It works fine with all other examples, but not if the “current month” is January.

How can I tackle this?
Is there another possibility even without the New Dictionary?

Thanks for your support in advance! :slight_smile:

Juli

Hello @Juli

Please try this with Modify Date Actvitiy.

Thanks

Hello @Juli ,

Please use AddMonths(-1) to get the previous month. Do not just subtract 1.
Also, please convert the argument of MonthName to DateTime

Example:

image

Hope it solves the issue!
Best regards,
Marius

Hi @Marius_Puscasu,

Thanks!
Of course, the AddMonths.
TestMonthVar actually was in DateTime already, so conversion was not necessary.
I got all the correct results.
Sometimes it’s just one tiny thing. :slight_smile:

@Rahul_Unnikrishnan
Thank you too, didn’t know the Modify Date activity yet.

Hi @Juli

you could try an alternative approach to avoid the dictionary method

image

str_quarter =

"Q"+Math.Ceiling(TestMonthVar.Month/3).ToString
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.