cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Converting Date to Quarters

Good Day Everyone,

 

I am needing some assistance with converting current date to the current quarter and taking the current quarter date to define which months are being looked over. The data is from SharePoint, in case that's relevant.

 

To go in further depth of what I mean, I know the syntax for getting the current date/time in PowerApps. Is there a way I can convert the date to text and auto populate it indefinitely? (I.E. the current day is 05/04/2018. Based on the month of May (05), we are in Q2 (Quarter 2). Therefor the text field will produce Q2, not 05/04/2018. In 3 months, it will be 08/04/2018, meaning we will be in Q3 (Quarter 3). And this continues even into the next year, and so on.)

 

The other question added on to this would be, is there any way to get PowerApps to understand that if we were in Q2, a text field can auto populate the previous quarter that is undergoing inspection? (I.E. We are in Q2, but the form is about Q1 (Jan., Feb., Mar.), so the text field will show Q1 instead of current Quarter.)

 

I hope this explanation made sense. If there is any extra information that may be needed to solve these, please let me know.

 

Thank you (P.S. I didn't know if this was a flow, formula, or rule/condition/action, so I kept it in General Questions)

1 ACCEPTED SOLUTION

Accepted Solutions
ericonline
Community Champion
Community Champion

Hello @Anonymous, 

 

I needed a similar solution to divide the year into halves. You could adapt it to your needs. Here is what I did: 

 

  1. At first I tried this using a Sharepoint calculated column. Bad idea. PowerApps doesn't play nice with SP Calc columns.
  2. Create the designation in the PowerApp itself.
    1. Choose a control to apply the following formula to. I chose the .OnVisible property of the screen but you could choose a button or other control as well. 

 

"Sets a variable for dividing year into two halves.";
If(Text(Today(),"[$-en-US]mm")="01" ||
    Text(Today(),"[$-en-US]mm")="02" ||
    Text(Today(),"[$-en-US]mm")="03" ||
    Text(Today(),"[$-en-US]mm")="04" ||
    Text(Today(),"[$-en-US]mm")="05" ||
    Text(Today(),"[$-en-US]mm")="06",
    Set(thisHalf,"1"),Set(thisHalf,"2")
    );

You might try something like: 

"Sets a variable for dividing year into quarters.";
If(Text(Today(),"[$-en-US]mm")="01" ||
    Text(Today(),"[$-en-US]mm")="02" ||
    Text(Today(),"[$-en-US]mm")="03" ,
    Set(thisQuarter,"1"),
Text(Today(),"[$-en-US]mm")="04" ||
    Text(Today(),"[$-en-US]mm")="05" ||
    Text(Today(),"[$-en-US]mm")="06" 
    Set(thisQuarter,"2")
    );...............etc.

...or, this may be a good candidate for the Switch statement. I don't have enough experience with this one to explain it. 

 

Props to @Paul_C for helping me with the above in this post.

View solution in original post

8 REPLIES 8
ericonline
Community Champion
Community Champion

Hello @Anonymous, 

 

I needed a similar solution to divide the year into halves. You could adapt it to your needs. Here is what I did: 

 

  1. At first I tried this using a Sharepoint calculated column. Bad idea. PowerApps doesn't play nice with SP Calc columns.
  2. Create the designation in the PowerApp itself.
    1. Choose a control to apply the following formula to. I chose the .OnVisible property of the screen but you could choose a button or other control as well. 

 

"Sets a variable for dividing year into two halves.";
If(Text(Today(),"[$-en-US]mm")="01" ||
    Text(Today(),"[$-en-US]mm")="02" ||
    Text(Today(),"[$-en-US]mm")="03" ||
    Text(Today(),"[$-en-US]mm")="04" ||
    Text(Today(),"[$-en-US]mm")="05" ||
    Text(Today(),"[$-en-US]mm")="06",
    Set(thisHalf,"1"),Set(thisHalf,"2")
    );

You might try something like: 

"Sets a variable for dividing year into quarters.";
If(Text(Today(),"[$-en-US]mm")="01" ||
    Text(Today(),"[$-en-US]mm")="02" ||
    Text(Today(),"[$-en-US]mm")="03" ,
    Set(thisQuarter,"1"),
Text(Today(),"[$-en-US]mm")="04" ||
    Text(Today(),"[$-en-US]mm")="05" ||
    Text(Today(),"[$-en-US]mm")="06" 
    Set(thisQuarter,"2")
    );...............etc.

...or, this may be a good candidate for the Switch statement. I don't have enough experience with this one to explain it. 

 

Props to @Paul_C for helping me with the above in this post.

Anonymous
Not applicable

Thank you @ericonline! This did not completely help me, since the dates were not associated with Sharepoint itself. I was actually able to get the form to work through tweaking the information you've offered and many nested formulas, similar to Excel's formulas. For future reference when using tables, I will definitely be using your solution.

Anonymous
Not applicable

You could also use the Switch() function instead of nested ifs, if you'd like to make the code easer to handle.

You can just use  Set(currentquarter, if(month(today())=1, "quarter 1" etc

DGreening
Frequent Visitor

 

"Q" & RoundUp(Month(<date>')/3,0)

MrThompson
Frequent Visitor

If(
    Month(Now())<=3,
        Set(thisQuarter,"1"),
    Month(Now())>=04 && Month(Now())<=06,
        Set(thisQuarter,"2"),
    Month(Now())>=07 && Month(Now())<=09,
        Set(thisQuarter,"3"),
    Month(Now())>=10,
        Set(thisQuarter,"4")
)

This is really clever!

FadyJnJ
New Member

Another way to get the Quarter is to divide the month by 3 and round the result up.

RoundUp(Month(Date)/3,0)

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,619)