Forum Discussion

EmWy24's avatar
EmWy24
Regular Visitor
1 year ago
Solved

Working days in current month

I am looking for a formula to calculate the number of working days in the current month.  My source is a database, so I am unable to create a calendar table or use the NETWORKDAY function unfortunate...
  • grazitti_sapna's avatar
    grazitti_sapna
    1 year ago

    Since you cannot use CALENDAR or GENERATESERIES, you can take a different approach by iterating over a range of days using a loop-like function. Try below solution

     

    WorkingDays_CurrentMonth =
    VAR StartDate = DATE(YEAR(TODAY()), MONTH(TODAY()), 1)
    VAR EndDate = EOMONTH(StartDate, 0)
    VAR DaysCount =
    SUMX(
    ADDCOLUMNS(
    SELECTCOLUMNS(UNION(SELECTCOLUMNS({1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31},
    "Offset", [Value])
    ),
    "Date", StartDate + [Offset] - 1,
    "Weekday", WEEKDAY(StartDate + [Offset] - 1, 2)
    ),
    IF([Date] <= EndDate && [Weekday] < 6, 1, 0)
    )
    RETURN DaysCount

     

    ๐ŸŒŸ I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
    ๐Ÿ’ก Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
    ๐ŸŽ– As a proud SuperUser and Microsoft Partner, weโ€™re here to empower your data journey and the Power BI Community at large.
    ๐Ÿ”— Curious to explore more? [Discover here].
    Letโ€™s keep building smarter solutions together!