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
Tprogrammer
New Member

calculate count of specific day of week

hi, i would like to know how to calculate count of an specific day of week.

Ex:   (2018-01-01 to 2018-12-31 , "Monday")

result: 52.

 

1 ACCEPTED SOLUTION

@Tprogrammer

 

Try this

 

CountMonday =
VAR StartDate =
    DATE ( 2018, 1, 1 )
VAR EndDate =
    DATE ( 2018, 12, 31 )
VAR Temp =
    ADDCOLUMNS (
        GENERATESERIES ( StartDate, EndDate ),
        "WeekDay", WEEKDAY ( [Value], 2 )
    )
RETURN
    COUNTROWS ( FILTER ( Temp, [WeekDay] = 1 ) )

Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
jthomson
Solution Sage
Solution Sage

Try looking into the WEEKDAY function - say you've got a calendar table that runs through 2018, the DAX function calculate(countrows[DateTable],weekday([datefield])=2) should return what you're looking for

i need the count between two dates.

@Tprogrammer

 

Try this

 

CountMonday =
VAR StartDate =
    DATE ( 2018, 1, 1 )
VAR EndDate =
    DATE ( 2018, 12, 31 )
VAR Temp =
    ADDCOLUMNS (
        GENERATESERIES ( StartDate, EndDate ),
        "WeekDay", WEEKDAY ( [Value], 2 )
    )
RETURN
    COUNTROWS ( FILTER ( Temp, [WeekDay] = 1 ) )

Regards
Zubair

Please try my custom visuals

Hi,

 

Would it be possible to amend the solution below to return 0 if there are no Mondays within the date range provided?

Currently it generates an error 'Calculation error in measure, The arguments in GenerateSeries function cannot be blank'

 

I am trying to use it to record which days were covered by an absence period, but as these periods can be less than a week, there isnt necessarily a Monday in the date range I am providing.

 

I tried changing the final line to :-

if(COUNTROWS ( FILTER(Temp,[Weekday] = 1)) = BLANK(),BLANK(),(COUNTROWS(FILTER(temp,[Weekday] = 1))

 

However this clearly isnt correct as it doesnt work,

Any assistance would be really appreciated.

Thanks

 

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.