cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TB05
Helper III
Helper III

Creating automated pay period selection

Hi,

I'm hoping someone could point me in the right direction....

I'm building a timesheet and right now the pay period is setup to manually enter it...using start dates and end dates, and user just selects the pay period from a dropdown list.  What I would like to achieve is to have the pay period automatic (no initial setup).  

I'm not clear on how to start as we have semi monthly pay, Starting on 1st of Month and the 16th to the end of the month.

I do have a variable created in a calendar that gets the first of the month called varFirstDayofMonth ( = 1).  

I'm assuming a forall and sequence but not clear how to put it together with the two starting pay period dates each month.  Any ideas or direction would be great.  Thanks for your help.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi @TB05 

 

Set the Default property of Dropdown to

With(
    {
        CurrentDate: Day(Now()),
        StartMonth: DateValue(Month(Now()) & "/1/" & Year(Now())),
        FirstHalfEndMonth: DateValue(Month(Now()) & "/15/" & Year(Now())),
        SecondHalfStartMonth: DateValue(Month(Now()) & "/16/" & Year(Now())),
        MonthEnd: DateAdd(
            DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
            -1,
            Days
        )
    },
    If(
        CurrentDate < 16,
        StartMonth & " - " & FirstHalfEndMonth,
        SecondHalfStartMonth & " - " & MonthEnd
    )
)

 

StalinPonnusamy_0-1636567640485.png

StalinPonnusamy_1-1636567664980.png

 

 

View solution in original post

We need to create 2 another variables to store StartDate and End Date. Set OnVisible property of screen to 

 

Set(
    varPayPeriodSelectedDropdownStartDate,
    With(
        {
            CurrentDate: Day(Now()),
            StartMonth: DateValue(Month(Now()) & "/1/" & Year(Now())),
            SecondHalfStartMonth: DateValue(Month(Now()) & "/16/" & Year(Now()))
        },
        If(
            CurrentDate < 16,
            StartMonth,
            SecondHalfStartMonth
        )
    )
);
Set(
    varPayPeriodSelectedDropdownEndDate,
    With(
        {
            CurrentDate: Day(Now()),
            FirstHalfEndMonth: DateValue(Month(Now()) & "/15/" & Year(Now())),
            MonthEnd: DateAdd(
                DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
                -1,
                Days
            )
        },
        If(
            CurrentDate < 16,
            FirstHalfEndMonth,
            MonthEnd
        )
    )
);

 

And also OnChange property of payperiod dropdown to

Set(varPayPeriodSelectedDropdownStartDate, PayPeriodDropdown.Selected.StartDate);
Set(varPayPeriodSelectedDropdownEndDate, PayPeriodDropdown.Selected.EndDate);

View solution in original post

10 REPLIES 10
StalinPonnusamy
Community Champion
Community Champion

Hi @TB05 

 

I assume you have a dropdown to pick up the pay period like

StalinPonnusamy_0-1636523903393.png

Set the DefaultDate for the StartDate to

If(Value(PayPeriod.Selected.Value)=1, DateValue(Month(Now()) & "/1/" & Year(Now())),DateValue(Month(Now()) & "/16/" & Year(Now())))

 

Set the DefaultDate of EndDate to

If(
    Value(PayPeriod.Selected.Value) = 1,
    DateValue(Month(Now()) & "/15/" & Year(Now())),
    DateAdd(
        DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
        -1,
        Days
    )
)

 

Please let me know if anything is misunderstood.

 


Thanks,
Stalin - Learn To Illuminate

 

Hi, thank you for responding.

Yes, so currently I have a dropdown list that is populated  with pay period selection.

TB05_0-1636562022772.png

I want the dropdown pay period to default to the  pay period within the current date.

The dropdown title is a combination of a StartDate & EndDate.

Hi @TB05 

 

Set the Default property of Dropdown to

With(
    {
        CurrentDate: Day(Now()),
        StartMonth: DateValue(Month(Now()) & "/1/" & Year(Now())),
        FirstHalfEndMonth: DateValue(Month(Now()) & "/15/" & Year(Now())),
        SecondHalfStartMonth: DateValue(Month(Now()) & "/16/" & Year(Now())),
        MonthEnd: DateAdd(
            DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
            -1,
            Days
        )
    },
    If(
        CurrentDate < 16,
        StartMonth & " - " & FirstHalfEndMonth,
        SecondHalfStartMonth & " - " & MonthEnd
    )
)

 

StalinPonnusamy_0-1636567640485.png

StalinPonnusamy_1-1636567664980.png

 

 

View solution in original post

TB05
Helper III
Helper III

That worked great! 

TB05
Helper III
Helper III

@StalinPonnusamy  The solution works great for what I want but now, where the user is not selecting the payperiod as it is defaulted, how do I set the variable for the pay period?  As I'm using a variable through my app.  If user selects an item in the list, onchange I have the following:  

Set(varPayPeriodSelectedDropdown, Dropdown7.Selected); this is working but not set when user doesn't select.  I thought I could add this code to the app on visible screen and it would set the variable. How do I set the variable to the defaulted pay period if user does not select it?

StalinPonnusamy
Community Champion
Community Champion

Hi @TB05 

 

We can move the formula to OnVisible property of the screen then.

 

Set Onvisible property of the screen to

Set(
    varPayPeriodSelectedDropdown,
    With(
        {
            CurrentDate: Day(Now()),
            StartMonth: DateValue(Month(Now()) & "/1/" & Year(Now())),
            FirstHalfEndMonth: DateValue(Month(Now()) & "/15/" & Year(Now())),
            SecondHalfStartMonth: DateValue(Month(Now()) & "/16/" & Year(Now())),
            MonthEnd: DateAdd(
                DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
                -1,
                Days
            )
        },
        If(
            CurrentDate < 16,
            StartMonth & " - " & FirstHalfEndMonth,
            SecondHalfStartMonth & " - " & MonthEnd
        )
    )
);

 

Set Default Property of PayPeriod Dropdown to

varPayPeriodSelectedDropdown

 
Thanks,
Stalin - Learn To Illuminate

I made that change and am seeing the variable output to be the current Pay Period.  

Throughout this application, I was using the varPayPeriodSelectedDropdown.StartDate and *.EndDate, I have a lot of conditions and error checking based around that variable.  Using the solution provided I'm unable to achieve this.  I'm not making reference to the rest of the list (thisitem).  Any thoughts on how we can achieve that?

We need to create 2 another variables to store StartDate and End Date. Set OnVisible property of screen to 

 

Set(
    varPayPeriodSelectedDropdownStartDate,
    With(
        {
            CurrentDate: Day(Now()),
            StartMonth: DateValue(Month(Now()) & "/1/" & Year(Now())),
            SecondHalfStartMonth: DateValue(Month(Now()) & "/16/" & Year(Now()))
        },
        If(
            CurrentDate < 16,
            StartMonth,
            SecondHalfStartMonth
        )
    )
);
Set(
    varPayPeriodSelectedDropdownEndDate,
    With(
        {
            CurrentDate: Day(Now()),
            FirstHalfEndMonth: DateValue(Month(Now()) & "/15/" & Year(Now())),
            MonthEnd: DateAdd(
                DateValue(Month(Now()) + 1 & "/1/" & Year(Now())),
                -1,
                Days
            )
        },
        If(
            CurrentDate < 16,
            FirstHalfEndMonth,
            MonthEnd
        )
    )
);

 

And also OnChange property of payperiod dropdown to

Set(varPayPeriodSelectedDropdownStartDate, PayPeriodDropdown.Selected.StartDate);
Set(varPayPeriodSelectedDropdownEndDate, PayPeriodDropdown.Selected.EndDate);

View solution in original post

TB05
Helper III
Helper III

Thank you so much!  You have been unbelievably helpful.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,712)