cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AbubakrWorking
Helper I
Helper I

Get Start and End Date of all weeks of current year in Gallery View

Hello Community,

I am creating a time tracking app in which I need to show the start and end dates of all weeks of the current year in the gallery view. I have attached a screenshot for a better understanding. Any help would be appreciated.


1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

@AbubakrWorking 

I have post that describes how to obtain a dates and week numbers here.
http://powerappsguide.com/blog/post/get-start-date-from-week-number

 

If you set the Items property of your gallery to the following formula, that will give you the start and end dates for all weeks in 2021.

 

AddColumns(
    AddColumns(
        Sequence(52),
        "StartOfWeek",
        With(
            {
                year: 2021,
                weekNo: Value
            },
            With(
                {
                    weekDate: If(
                        ISOWeekNum(
                            Date(
                                year,
                                1,
                                1
                            )
                        ) < 1,
                        DateAdd(
                            Date(
                                year,
                                1,
                                1
                            ),
                            7 * (weekNo - 1)
                        ),
                        DateAdd(
                            Date(
                                year,
                                1,
                                1
                            ),
                            7 * weekNo
                        )
                    )
                },
                DateAdd(
                    weekDate,
                    -(Weekday(
                        weekDate,
                        StartOfWeek.MondayZero
                    )),
                    Days
                )
            )
        )
    ),
    "EndOfWeek",
    DateAdd(
        StartOfWeek,
        6
    )
)

 

timl_0-1636728921447.png

 

View solution in original post

2 REPLIES 2
CNT
Super User
Super User

@AbubakrWorking Start with the first day you want and use the DateAdd function to keep going till the last day,

Syntax

DateAdd( DateTime, Addition [, Units ] )

  • DateTime - Required. Date/time value to operate on.
  • Addition - Required. Number, in Units, to add to the DateTime.
  • Units - Optional. The type of Units to add: Milliseconds, Seconds, Minutes, Hours, Days, Months, Quarters, or Years. If not specified, Days are used.
timl
Super User
Super User

@AbubakrWorking 

I have post that describes how to obtain a dates and week numbers here.
http://powerappsguide.com/blog/post/get-start-date-from-week-number

 

If you set the Items property of your gallery to the following formula, that will give you the start and end dates for all weeks in 2021.

 

AddColumns(
    AddColumns(
        Sequence(52),
        "StartOfWeek",
        With(
            {
                year: 2021,
                weekNo: Value
            },
            With(
                {
                    weekDate: If(
                        ISOWeekNum(
                            Date(
                                year,
                                1,
                                1
                            )
                        ) < 1,
                        DateAdd(
                            Date(
                                year,
                                1,
                                1
                            ),
                            7 * (weekNo - 1)
                        ),
                        DateAdd(
                            Date(
                                year,
                                1,
                                1
                            ),
                            7 * weekNo
                        )
                    )
                },
                DateAdd(
                    weekDate,
                    -(Weekday(
                        weekDate,
                        StartOfWeek.MondayZero
                    )),
                    Days
                )
            )
        )
    ),
    "EndOfWeek",
    DateAdd(
        StartOfWeek,
        6
    )
)

 

timl_0-1636728921447.png

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

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