Skip to main content

Notifications

Community site session details
Power Apps - Building Power Apps
Answered

Need dynamic sequence - List of Weeks for current month

Like (0) ShareShare
ReportReport
Posted on 15 Feb 2024 16:36:27 by 323

(update) Hi all

 

is it possible to create a dynamic sequence for the number of weeks based on the current month?

which I then want to use for a drop-down/combo box control (Collection as item?)

 

currently using 

 

 

"Week " & RoundDown(
 (Day(Today()) - Day(DateValue("1/1/" & Year(Today()))) + Weekday(DateValue("1/1/" & Year(Today())) - 1)) / 7,
 0
) + 1

 

on a text label which just gives the current week number for the current month (this gives correct week)

 

  Issue:

ClearCollect(
 AvailableWeeks,
 AddColumns(
 Sequence(
 RoundUp(
 (Day(
 DateAdd(
 Date(
 Year(Today()),
 Month(Today()) + 1,
 1
 ),
 -1,
 TimeUnit.Days
 )
 ) -// Last day of the current month
 Day(
 Date(
 Year(Today()),
 Month(Today()),
 1
 )
 ) + 1 +// Day of the first day of the current month
 Weekday(
 Date(
 Year(Today()),
 Month(Today()),
 1
 ) - Day(
 Date(
 Year(Today()),
 Month(Today()),
 1
 )
 ) + 1
 )// Weekday of the first day of the current month
) / 7,
 0
 )
 ),
 "WeekNumber",
 "Week " & Value
 )
);

moerah_0-1708020393259.png

this gives 5 weeks which is wrong as February has 4 weeks 

 

any suggestion would be great 

 

thank you 😃

Categories:
  • moerah Profile Picture
    323 on 15 Feb 2024 at 18:29:22
    Re: Need dynamic sequence - List of Weeks for current month

    @LEGRANCHE Woww! Thank you so much 😀

     

    did not even have to use clear collect ,learn something new every day 

     

    this works perfect for my items

    With(
     {StartDate: Date(Year(Today()), Month(Today()), 1)},
     AddColumns(
     Filter(
     [1, 2, 3, 4, 5, 6],
     Value < 1 + ISOWeekNum(DateAdd(StartDate, 1, TimeUnit.Months)) - ISOWeekNum(StartDate)
     ),
     "WeekNumber",
     "Week " & Text(Value)
     )
    )

     

  • Verified answer
    LEGRANCHE Profile Picture
    on 15 Feb 2024 at 18:15:58
    Re: Need dynamic sequence - List of Weeks for current month

    Hi

     

    to get the number of weeks within the current month, you can use the following:

    With(
     {StartDate:Date(Year(Today()), Month(Today()),1)},
     ISOWeekNum(DateAdd(StartDate,1,TimeUnit.Months))-ISOWeekNum(StartDate)
    )

     

    Now to use it for the property items of drop-down, use the following:

    With(
     {StartDate:Date(Year(Today()), Month(Today()),1)},
     Filter([1,2,3,4,5,6],Value<1+ISOWeekNum(DateAdd(StartDate,1,TimeUnit.Months))-ISOWeekNum(StartDate))
    )

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 93 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard