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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
PrakashPalle
Helper I
Helper I

Number of Sundays in between dates

Hi Power BI Experts,

How to find number of sundays existed in between start & end dates.

Please share the dax code how to calculate number of sundays in output section. Thanks in advance.

 

PrakashPalle_0-1718440403894.png

 

1 ACCEPTED SOLUTION
foodd
Super User
Super User

Hello @PrakashPalle , the following DAX calculates the number of Sundays row by row when a Start Date and End date is supplied.

 

 

 

 

Number of Sundays = 
VAR NumOfWeeks = INT(DATEDIFF([StartDate], [EndDate], WEEK))
VAR NumOfSundays =
    COUNTROWS(
        FILTER(
            GENERATESERIES([StartDate], [EndDate], 1),
            WEEKDAY([Value]) = 1
        )
    )
RETURN
    IF(NumOfWeeks = 0, IF(WEEKDAY([StartDate]) = 1, 1, 0), NumOfSundays)

 

 

 

foodd_0-1718478730145.png





=-=-=-=-=-

If you find this insightful, please provide a Kudo and Accept this as a Solution so that others may find a Solution easier when searching.

View solution in original post

8 REPLIES 8
foodd
Super User
Super User

Hello @PrakashPalle , the following DAX calculates the number of Sundays row by row when a Start Date and End date is supplied.

 

 

 

 

Number of Sundays = 
VAR NumOfWeeks = INT(DATEDIFF([StartDate], [EndDate], WEEK))
VAR NumOfSundays =
    COUNTROWS(
        FILTER(
            GENERATESERIES([StartDate], [EndDate], 1),
            WEEKDAY([Value]) = 1
        )
    )
RETURN
    IF(NumOfWeeks = 0, IF(WEEKDAY([StartDate]) = 1, 1, 0), NumOfSundays)

 

 

 

foodd_0-1718478730145.png





=-=-=-=-=-

If you find this insightful, please provide a Kudo and Accept this as a Solution so that others may find a Solution easier when searching.

@foodd thanks for your reply. I tried to replicate the code i am getting below error. Please help.

PrakashPalle_0-1718518521971.png

 

Please upload your Excel source file, and your 

work in progress Power BI Desktop file.

Thanks @foodd , for the reply.

I have added startdate & endate blanks in your data. I am getting the same error. 

PrakashPalle_0-1718552958389.png

 

Please download, open, and refresh the PowerBI Desktop File attached to the reply with the Power Query M-Code.    There are no errors produced, and the data table was Entered as data in the PBIX itself.   Your original post does not reference Blank Rows, and as a result, the working M-Code produces no errors.   Please do reply with constructive feedback should you find that the Power BI Desktop file fails to load and display the desired results upon opening.

dulan_kavinda
Helper I
Helper I

Can you try with below DAX with the date column,

 

Is_Sunday =
IF(
WEEKDAY('TableName'[Date], 2) = 7,
1,
0
)

 

If you have 2 separate column for start date and end date in the table please let me know.

bhanu_gautam
Super User
Super User

@PrakashPalle , You can use the formula mentioned below to calculate Number of Sundays

 

Number of Sundays =
VAR StartDate = MIN('Table'[Start Date])
VAR EndDate = MAX('Table'[End Date])
VAR NumOfWeeks = INT(DATEDIFF(StartDate, EndDate, WEEK))
VAR NumOfSundays =
COUNTX(
GENERATESERIES(StartDate, EndDate, 1),
IF(WEEKDAY([Value]) = 1, 1, 0)
)
RETURN
IF(NumOfWeeks = 0, IF(WEEKDAY(StartDate) = 1, 1, 0), NumOfSundays)




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

Proud to be a Super User!




LinkedIn






Thanks @bhanu_gautam for the reply.

I replicated the dax which you have shared, but unfortunately the expression is not giving the correct output. Below screen shot for your reference.

 

PrakashPalle_0-1718467388267.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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