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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
goodhvnting
Frequent Visitor

Calculate number of weekends (Fridays and Saturdays) between two dates

Hello!

 

I've been searching this community for a solution but I don't believe this has been answered in my specific scenario. Hoping someone can help me with the following problem:

 

I want to calculate the number of weekend nights (Friday and Saturdays) between two dates. I have the following columns:

 

PERMIT_START_DT
PERMIT_END_DT

 

I'd like to create a new column (not measure) that tells me how many weekend nights are between those two date columns. 

 

Much appreciated! 

1 ACCEPTED SOLUTION

Somehow I was able to solve my own question! Thank you to davehus for trying to help me. 

 

This is the formula I used to get the answer to my question: 

 

Weekend_Nights = COUNTROWS(FILTER(CALENDAR(RAP_Permits_to_Postal_Code[PERMIT_START_DT],RAP_Permits_to_Postal_Code[PERMIT_END_DT]), WEEKDAY([Date]) in {6,7} ))

View solution in original post

8 REPLIES 8
davehus
Memorable Member
Memorable Member

Hi @goodhvnting ,

 

Are you happy for the column to only update on refresh as this will be the case with a calculated column?

 

 

Yes, that works for me. Thank you! 

This is with DAX. You can do it with powerquery either. Swap Date() for your Permit_start

 

IsWeekend = IF(AND(OR(WEEKDAY('Date Table'[DateKey])=7,WEEKDAY('Date Table'[DateKey])=1),AND('Date Table'[DateKey]>date(2021,01,01),'Date Table'[DateKey]<DATE(2021,01,31))),1,0)
 
Did I help you today? Please accept my solution and hit the Kudos button.
 

Thanks for the response. 

Finding this solution a little confusing... can you confirm that the DAX formula is used in the "New Column" function? 

Where would the PERMIT_START_DT and PERMIT_END_DT columns be used? These columns are in a sepearate table not in a "Date Table".

 

Appreciate your time. 

Hi @goodhvnting , Yes it is. So the calculation is checking if the weekday is a Friday OR Saturday and the dates are between the start AND end date.  I've modified and test with a separate table and it works.

IsWeekend =
IF (
    AND (
        OR (
            WEEKDAY ( 'Date Table'[DateKey] ) = 6,
            WEEKDAY ( 'Date Table'[DateKey] ) = 7// Is it Friday or Saturday
        ),
        AND (
            'Date Table'[DateKey] > MAX ( Parameter[PERMIT_START_DT] ),
            'Date Table'[DateKey] < MAX ( Parameter[PERMIT_END_DT] )
        )
    ),
    1,
    0
)

 

davehus_0-1662495722590.png

 

Thanks again for your response. 

Apologies, my question may not have been very clear. 


I am trying to count the number of Fridays and Saturdays that occur between two dates. Not if it is a Friday or Saturday. 

Example:  

PERMIT_START_DTPERMIT_END_DT
Friday, August 23, 2019Sunday, August 25, 2019
Thursday, August 01, 2018Friday, August 03 2018
Friday, August 22, 2014Sunday, August 24, 2014

 

I want to create a new column using a DAX formula that will count the total number of Fridays AND saturdays between those 2 dates. It should look something like this: 

 

Weekend_Nights
2
1
2

 

Thanks again for your time and consideration. Truly appreciate it. 

Somehow I was able to solve my own question! Thank you to davehus for trying to help me. 

 

This is the formula I used to get the answer to my question: 

 

Weekend_Nights = COUNTROWS(FILTER(CALENDAR(RAP_Permits_to_Postal_Code[PERMIT_START_DT],RAP_Permits_to_Postal_Code[PERMIT_END_DT]), WEEKDAY([Date]) in {6,7} ))

Hi @goodhvnting , 

You would have got the same result once the columnn was dragged into the canvas. See below.

 

davehus_0-1662499172683.png

 

Glad you got sorted.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors