Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
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.
Solved! Go to Solution.
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)
=-=-=-=-=-
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.
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)
=-=-=-=-=-
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.
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.
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.
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.
@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)
Proud to be a Super User! |
|
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
123 | |
78 | |
49 | |
38 | |
37 |
User | Count |
---|---|
196 | |
80 | |
70 | |
51 | |
42 |