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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Sum between Range

I have a table called Raw_table that is like the one below, and want to calculate the days between the two excluding weekends. 

Start DateDue Date
1-1-202013-1-2020
6-1-202012-1-2020

 

I created another table using the Calender auto function and numbered the days with 1 for weekdays and 0 for weekends. I then tried to use a query like this.

 

 

 

WorkDays = CALCULATE(SUM('Calendar'[Weekday],FILTER('Calendar',(DATESBETWEEN(Raw_table[Start Date],RawTable[Start Date],RawTable[Due Date])))

 

 

 

This fails but there must be a way of doing it? I have found a number of resources on the web for doing something like the excel NETWORKDAYS but cant get them to work. is there a way using what i have to get it to work 

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Hi, @Anonymous , you may want to try this measure,

NetWorkdays Measure = 
COUNTROWS (
    FILTER (
        DATESBETWEEN (
            'Calendar'[Date],
            MIN ( Raw_table[Start Date] ),
            MIN ( Raw_table[Due Date] )
        ),
        WEEKDAY ( 'Calendar'[Date], 2 ) < 6
    )
)

Screenshot 2020-10-27 210538.png

In addition, here's a Power Query solution

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ11DUyMDJQ0lEyNIaxY3WilcyQJIzgErEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"Due Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"Due Date", type date}}, "fr"),

    #"Added Custom" = Table.AddColumn(#"Changed Type", "NetWorkdays", each 
        List.Accumulate(
            {0..Duration.Days([Due Date]-[Start Date])},
            0,
            (s,c) => if Date.DayOfWeek(Date.AddDays([Start Date], c), Day.Monday)>4 then s else s+1
        )
    )
in
    #"Added Custom"

Screenshot 2020-10-27 210928.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Is there a way to get the measure as a column? As I would like to be able to return the average of the number of days? 

Also how would i implement the power query i am new to those and as such dont know how i would implement it with my tables rather than the Json?

DAX formula for calculated column

NetWorkdays CC = 
COUNTROWS (
    FILTER (
        DATESBETWEEN (
            'Calendar'[Date],
            Raw_table[Start Date],
            Raw_table[Due Date]
        ),
        WEEKDAY ( 'Calendar'[Date], 2 ) < 6
    )
)

Screenshot 2020-10-28 130552.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

thank you but when i try i get the following error:
A circular dependency was detected: Raw_table[Column 2], Calendar[Date], Calendar[Calendar-0ae25540-d45c-4ff4-ac09-cd6af6c3ca4a], 13a0b372-8077-49fa-9674-c2b965903db3, Raw_New_Layout_[Task Name], Raw_New_Layout_[Raw_New_Layout_-f197bdcd-f316-4285-9ba6-931a37a888d8], Raw_table[Column 2].

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors