Forum Discussion

jb123's avatar
jb123
Frequent Visitor
9 years ago
Solved

Column that Calculates Business Days

Hi,

 

I need to create a column that calculates the business days. I have this working that displays the calendar days in a column and I just need to tweek it to exclude weekends:

 

Days =
SWITCH (
    TRUE (),
    'Velocity'[DashboardCreationDate] <Velocity[Completed Date] , DATEDIFF ('Velocity'[DashboardCreationDate], 'Velocity'[Completed Date], DAY ),
    'Velocity'[DashboardCreationDate] > 'Velocity'[Completed Date], DATEDIFF ('Velocity'[Completed Date], 'Velocity'[DashboardCreationDate], DAY ) * -1,
    0
)

 

TIA!!!

  • Anonymous's avatar
    Anonymous
    9 years ago

    jb123,

    Use the following DAX to create date table and check if you get any errors.

    Date =
    ADDCOLUMNS (
    CALENDAR (DATE(2000,1,1), DATE(2025,12,31)),
    "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
    "Year", YEAR ( [Date] ),
    "Monthnumber", FORMAT ( [Date], "MM" ),
    "YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
    "YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
    "MonthNameShort", FORMAT ( [Date], "mmm" ),
    "MonthNameLong", FORMAT ( [Date], "mmmm" ),
    "DayOfWeekNumber", WEEKDAY ( [Date] ),
    "DayOfWeek", FORMAT ( [Date], "dddd" ),
    "DayOfWeekShort", FORMAT ( [Date], "ddd" ),
    "Quarter", "Q" & FORMAT ( [Date], "Q" ),
    "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )



    Regards,

  • Anonymous's avatar
    Anonymous
    9 years ago

    jb123,

    Use the following DAX instead.

    Days excluding Weekends = IF(ISBLANK(Velocity[Completed Date])||ISBLANK(Velocity[DashboardCreationDate]),BLANK(),SWITCH (
        TRUE (),
    'Velocity'[DashboardCreationDate] <Velocity[Completed Date] , CALCULATE(SUM('Date'[IsWorkDay]),DATESBETWEEN('Date'[Date],Velocity[DashboardCreationDate],Velocity[Completed Date] )),
        'Velocity'[DashboardCreationDate] > 'Velocity'[Completed Date],CALCULATE(SUM('Date'[IsWorkDay]),DATESBETWEEN('Date'[Date],Velocity[Completed Date],Velocity[DashboardCreationDate] )) * -1,
        0
    ))
    



    Regards,

9 Replies

  • Hi jb123,

    From your formula I cannot perceive where you want to take out the bussines days but if you use the WEEKDAY formula you can then exclude the weekday = 1 (Sunday) or 7 (saturday).

    Regards,
    MFelix
  • Anonymous's avatar
    Anonymous
    Not applicable

    jb123,

    Firstly, create a date table in Power BI Desktop following the instructions in this blog.

    Secondly, create a new column in the date table using the DAX below.

    IsWorkDay = SWITCH(WEEKDAY('Date'[Date]),1,0,7,0,1)

    Thirdly, create a new column using the following formula in  your original table.

    Days excluding Weekends = SWITCH (
        TRUE (),
        'Velocity'[DashboardCreationDate] <Velocity[Completed Date] , CALCULATE(SUM('Date'[IsWorkDay]),DATESBETWEEN('Date'[Date],Velocity[DashboardCreationDate],Velocity[Completed Date] )),
        'Velocity'[DashboardCreationDate] > 'Velocity'[Completed Date],CALCULATE(SUM('Date'[IsWorkDay]),DATESBETWEEN('Date'[Date],Velocity[Completed Date],Velocity[DashboardCreationDate] )) * -1,
        0
    )





    Regards,

    • jb123's avatar
      jb123
      Frequent Visitor

      Thanks I will give this a try and see if I can get it to work.

    • jb123's avatar
      jb123
      Frequent Visitor

      The syntax to create a date table in the blog is incorrect.  If you click on new table from moedling and do a copy and paste of the following:

       

      Date =CALENDAR (DATE(2000;1;1); DATE(2025;12;31))

       

      You get an error saying the syntax is incorrect so i thought ok I should copy and paste all of it so I did a copy and paste of this instead

       

      Date =
      ADDCOLUMNS (
      CALENDAR (DATE(2000;1;1); DATE(2025;12;31));
      "DateAsInteger"; FORMAT ( [Date]; "YYYYMMDD" );
      "Year"; YEAR ( [Date] );
      "Monthnumber"; FORMAT ( [Date]; "MM" );
      "YearMonthnumber"; FORMAT ( [Date]; "YYYY/MM" );
      "YearMonthShort"; FORMAT ( [Date]; "YYYY/mmm" );
      "MonthNameShort"; FORMAT ( [Date]; "mmm" );
      "MonthNameLong"; FORMAT ( [Date]; "mmmm" );
      "DayOfWeekNumber"; WEEKDAY ( [Date] );
      "DayOfWeek"; FORMAT ( [Date]; "dddd" );
      "DayOfWeekShort"; FORMAT ( [Date]; "ddd" );
      "Quarter"; "Q" & FORMAT ( [Date]; "Q" );
      "YearQuarter"; FORMAT ( [Date]; "YYYY" ) & "/Q" & FORMAT ( [Date]; "Q" )
      )

       

      Again I get a syntax error.  The exact error message is "The syntax for ';' is incorrect. (DAX(CALENDAR (DATE(2000;1;1); DATE(2025;12;31))))."

       

       

      Any suggestions?

      • Anonymous's avatar
        Anonymous
        Not applicable

        jb123,

        Use the following DAX to create date table and check if you get any errors.

        Date =
        ADDCOLUMNS (
        CALENDAR (DATE(2000,1,1), DATE(2025,12,31)),
        "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
        "Year", YEAR ( [Date] ),
        "Monthnumber", FORMAT ( [Date], "MM" ),
        "YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
        "YearMonthShort", FORMAT ( [Date], "YYYY/mmm" ),
        "MonthNameShort", FORMAT ( [Date], "mmm" ),
        "MonthNameLong", FORMAT ( [Date], "mmmm" ),
        "DayOfWeekNumber", WEEKDAY ( [Date] ),
        "DayOfWeek", FORMAT ( [Date], "dddd" ),
        "DayOfWeekShort", FORMAT ( [Date], "ddd" ),
        "Quarter", "Q" & FORMAT ( [Date], "Q" ),
        "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" )



        Regards,