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

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

Reply
Banan
Frequent Visitor

Different days usinf custom column

Hi,

I'm using DirectQuery and i want to calculate the start date - end date without the weekend (Friday and Saturday) through a custom column. Can you help me?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Banan 

When you use the calendar() funciton, then first date you need to input the start date, then second date you need to input the end date, the end date need to be greater than the start date, for the error message you offered , you didn't put the start date in the first date. You can refer to the following link.

CALENDAR function (DAX) - DAX | Microsoft Learn

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Banan 

If you want to add the custom column in power query in direct query mode,  the custom column cannot be applied, becuse in direct mode, the steps in power query have limitations,you can refer to the following link.

https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-directquery-about#data-transformatio...

The direct mode have limitations in transform data and data modeling, you can refer to the following link.

https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-directquery-about#modeling-limitatio...

The best way is to change the direct mode to import mode, then you can use the custom column, you can refer to the following sample.(the connect mode is import)

Sample data 

vxinruzhumsft_0-1704678895346.png

Add a custom column

 

List.Sum(List.Transform(List.Dates([dt1],Duration.Days([dt2]-[dt1])+1,#duration(1,0,0,0)),each if Date.DayOfWeek(_,Day.Sunday)<5 then 1 else 0))

 

Output

vxinruzhumsft_1-1704679111801.png

If you cannot change the mode to import mode, please consider to create a measure, you can refer to the following measure.

 

Measure =
VAR a =
    ADDCOLUMNS (
        CALENDAR ( MIN ( SQLTest[dt1] ), MAX ( SQLTest[dt2] ) ),
        "Weekday", WEEKDAY ( [Date], 2)
    )
RETURN
    COUNTROWS ( FILTER ( a, [Weekday] <> 5 && [Weekday] <> 6 ) )

 

Output

vxinruzhumsft_2-1704679235923.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

There is no error in the code, but when I create a chart and use the new measure, this message appears " MdxScript(Model) (8,8) calculation error in measure "table name[Measure]: the start date in calender function can not be later than end date". 

Note: The weekend in our country is Friday and Saturday

There is no error in the code, but when I create a chart and use the new measure, this message appears " MdxScript(Model) (8,8) calculation error in measure "table name[Measure]: the start date in calender function can not be later than end date". 

Note: The weekend in our country is Friday and Saturday

Anonymous
Not applicable

Hi @Banan 

When you use the calendar() funciton, then first date you need to input the start date, then second date you need to input the end date, the end date need to be greater than the start date, for the error message you offered , you didn't put the start date in the first date. You can refer to the following link.

CALENDAR function (DAX) - DAX | Microsoft Learn

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.