I am having a trouble creating a calendar app in PowerApps and I can't advance to the next month correctly

76 Views Asked by At

I am creating a calendar app in PowerApps for a project.

Everything was doing just fine, until I got to the part where I needed to create the button to skip to the next month:

Set(varVideoMonth; DateAdd(varVideoMonth; Month(Today())));; Set(varVideoFirstDayView; DateAdd(varVideoMonth; - Weekday(varVideoMonth) + 1));;

This is my code right now. It is supposed to, when clicked, change the first day viewed in the calendar, so it should be 11/26, then 12/31, then 01/28, and on and on. But what this code is actually doing is advancing only one week, so it is showing 11/12 instead of the first result that should be 11/26.

I was doing this calendar based on a YouTube tutorial, but the video is from 2 years ago and I can't find help in any AI bot (I tried GPT and Bard). Please someone knows how to do it?

I tried changing the variables, and changing the numbers counters, but all that I got was messing up the days and weeks. Right now my project is getting correctly the days and weekdays, but my only problem is advancing the whole month instead of the week.

1

There are 1 best solutions below

0
aMir Kazemi On

It looks like there might be a small issue with the way you're updating the varVideoMonth variable. The DateAdd function is adding the current month instead of advancing to the next month. To fix this, you can use DateAdd with the 1 parameter for the number of months to add.

Here's the corrected code:

Set(varVideoMonth, DateAdd(varVideoMonth, 1))
Set(varVideoFirstDayView, DateAdd(varVideoMonth, - Weekday(varVideoMonth) + 1))

This way, when you click the button, it will add 1 month to the varVideoMonth variable, and then set varVideoFirstDayView to the first day of that new month.

If this still doesn't work as expected, you might want to check the initial value of varVideoMonth and make sure it's correctly set to the current date or the date you want as a starting point.

For debugging purposes, you can use Text function to display the values of your variables in a label or some other visible element:

Set(varVideoMonth, DateAdd(varVideoMonth, 1))
Set(varVideoFirstDayView, DateAdd(varVideoMonth, - Weekday(varVideoMonth) + 1))

// Display the values for debugging
Set(Label1.Text, Text(varVideoMonth, "MM/DD"))
Set(Label2.Text, Text(varVideoFirstDayView, "MM/DD"))

This way, you can observe the changes in the values of varVideoMonth and varVideoFirstDayView as you click the button and identify any unexpected behavior.