Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Difference between two dates with excluding weekends.

Dear Team,

Please help me solve for construct below query.

IDStatusStart DateEnd DateNo: of Days
201Done10/03/202210/06/20223
205Approved10/04/2022 9(when end date is blank we need to consider Today()-Start Date.)
206Deployed10/04/2022 9(when end date is blank we need to consider Today()-Start Date.)
207Done09/26/202209/29/20223

 

Please guide me how to write DAX fuction for above query.

 

Advance Thanks,

Venkata.

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

    Assum that there is one date dimension table in your model, you can create a calculated column as below to get the number of days between two dates. Please find the details in the attachment.

    No.of Days =
    VAR _enddate =
        IF ( ISBLANK ( 'Table'[End Date] ), TODAY (), 'Table'[End Date] )
    RETURN
        CALCULATE (
            COUNTROWS ( 'Date' ),
            DATESBETWEEN ( 'Date'[Date], 'Table'[Start Date], _enddate ),
            FILTER ( 'Date', WEEKDAY ( 'Date'[Date], 2 ) < 6 )
        )

    In addition, you can refer the following blog to get it by DAX or Power Query method...

    Calculate Workdays Between Two Dates In Power BI

    Best Regards

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Assum that there is one date dimension table in your model, you can create a calculated column as below to get the number of days between two dates. Please find the details in the attachment.

    No.of Days =
    VAR _enddate =
        IF ( ISBLANK ( 'Table'[End Date] ), TODAY (), 'Table'[End Date] )
    RETURN
        CALCULATE (
            COUNTROWS ( 'Date' ),
            DATESBETWEEN ( 'Date'[Date], 'Table'[Start Date], _enddate ),
            FILTER ( 'Date', WEEKDAY ( 'Date'[Date], 2 ) < 6 )
        )

    In addition, you can refer the following blog to get it by DAX or Power Query method...

    Calculate Workdays Between Two Dates In Power BI

    Best Regards