Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How Many Certain Weekdays are in a Month

Probably has been discussed, but looking for some assistance as i have not found anything online.  Is there a way to add a custom column to a specific date (ex. 9/1/2021) and it returns how many "Mondays" are in that month?

 

 

Capture.PNG

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is a DAX column expression that shows one way to do it.  Replace T1 with your actual table name.  Note that you should make your column type Date instead of type DateTime.

 

Mondays =
VAR thisdate = T1[Week]
VAR thisEOM =
    EOMONTH ( thisdate0 )
VAR thisCalendar =
    CALENDAR ( thisdatethisEOM )
VAR result =
    COUNTROWS ( FILTER ( thisCalendarWEEKDAY ( [Date] ) = 2 ) )
RETURN
    result

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
watkinnc
Super User
Super User

@Jakinta pretty slick!


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
mahoneypat
Employee
Employee

Here is a DAX column expression that shows one way to do it.  Replace T1 with your actual table name.  Note that you should make your column type Date instead of type DateTime.

 

Mondays =
VAR thisdate = T1[Week]
VAR thisEOM =
    EOMONTH ( thisdate0 )
VAR thisCalendar =
    CALENDAR ( thisdatethisEOM )
VAR result =
    COUNTROWS ( FILTER ( thisCalendarWEEKDAY ( [Date] ) = 2 ) )
RETURN
    result

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Jakinta
Solution Sage
Solution Sage

You can add this step to ypur query.

I have used Date.StartOfMonth as caution in case the date in Week column is not 1st day of month.

 

= Table.AddColumn( PriorStepName , "MondaysCount", each let s=Number.From(Date.StartOfMonth(Date.From([Week]))), e=Number.From(Date.EndOfMonth(Date.From([Week]))), Dates=List.Transform({s..e}, Date.From) in List.Count( List.Select( Dates, each Date.DayOfWeek(_)=1 ) ) )

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors