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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lewisgrantevans
Regular Visitor

Help with calculating business days and decimal places

Hello,

 

I have created a Calendar table in Power Bi so I can track working days and this is working as intended. I am then using the following DAX to create a 'turnaround business days' column -

 

Turnaround Business Days =
CALCULATE(
COUNTROWS('Calendar'),
DATESBETWEEN(
'Calendar'[Date],
'Case Assignment History'[Entry_Time__c],
'Case Assignment History'[Exit_Time__c] ),
'Calendar'[IsWorkingDay] = TRUE,
ALLSELECTED( 'Case Assignment History' ))
 
This is working and creating a 'Turnaround Business Days' column and removing weekends, however, I need to incorporate 2 decimal points into the calculation, because everything is being rounded up or down. For the following example, the desired result is '0.24', rather than '1' -
 
Entry_Time__cExit_Time__cElapsed_Time_Days__cTurnaround Business DaysExpected Result
12/08/2019 07:4812/08/2019 13:270.2410.24

 

Any help is much appreciated!

 

Thanks

 

1 ACCEPTED SOLUTION

@lewisgrantevans 

I foud the issue, I set it as TRUE for working day, it should be false:

Turnaround Business Days = 
var __workdays = 
    CALCULATE(
        COUNTROWS('Calendar'),
        DATESBETWEEN(
            'Calendar'[Date],
            'Case Assignment History'[Entry_Time__c],
            'Case Assignment History'[Exit_Time__c] ),
            'Calendar'[IsWorkingDay] = FALSE
    )
var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)

return
  __days - __workdays

Fowmy_0-1624630245044.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

9 REPLIES 9
Fowmy
Super User
Super User

@lewisgrantevans 

Can you check if this calculated column works for you?

Turnaround Business Days = 
var __workdays = 
    CALCULATE(
        COUNTROWS('Calendar'),
        DATESBETWEEN(
            'Calendar'[Date],
            'Case Assignment History'[Entry_Time__c],
            'Case Assignment History'[Exit_Time__c] ),
            'Calendar'[IsWorkingDay] = TRUE
    )
var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)
var __result = IF( __days >= __workdays , __days - __workdays ) 
return

Fowmy_0-1624621110620.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I'm getting a syntax error unfortunately -

 

The syntax for ')' is incorrect. (DAX(var __workdays = CALCULATE( COUNTROWS('Calendar'), DATESBETWEEN( 'Calendar'[Date], 'Case Assignment History'[Entry_Time__c], 'Case Assignment History'[Exit_Time__c] ), 'Calendar'[IsWorkingDay] = TRUE )var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)var __result = IF( __days >= __workdays , __days - __workdays ) return)).

 

syntax error.JPG

 

Thanks!

Turnaround Business Days = 
var __workdays = 
    CALCULATE(
        COUNTROWS('Calendar'),
        DATESBETWEEN(
            'Calendar'[Date],
            'Case Assignment History'[Entry_Time__c],
            'Case Assignment History'[Exit_Time__c] ),
            'Calendar'[IsWorkingDay] = TRUE
    )
var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)
var __result = IF( __days >= __workdays , __days - __workdays ) 
return
    __result
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I think we're almost there!

 

It appears to be calculating the wrong way around, so anything with a 'negative' value is returning a blank. Your column is 'Turnaround Business Days 2' -

 

Entry_Time__cExit_Time__cElapsed_Time_Days__cTurnaround Business DaysTurnaround Business Days 2
28/06/2019 09:1004/07/2019 09:336.0251.02
05/06/2019 10:0305/06/2019 15:180.221 
19/06/2019 08:3519/06/2019 11:110.111 
20/06/2019 14:1020/06/2019 15:230.051 
05/07/2019 13:2305/07/2019 15:150.081 
08/07/2019 15:4015/07/2019 10:186.7860.78
09/07/2019 13:4409/07/2019 14:540.051 
11/07/2019 08:0522/07/2019 14:1511.2683.26
12/07/2019 11:1915/07/2019 09:362.9320.93
22/07/2019 13:2522/07/2019 15:420.11 
15/07/2019 08:2115/07/2019 11:050.111 

@lewisgrantevans 

If you want the negative value, it will be shown as follows

Turnaround Business Days = 
var __workdays = 
    CALCULATE(
        COUNTROWS('Calendar'),
        DATESBETWEEN(
            'Calendar'[Date],
            'Case Assignment History'[Entry_Time__c],
            'Case Assignment History'[Exit_Time__c] ),
            'Calendar'[IsWorkingDay] = TRUE
    )
var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)

return
   __days - __workdays 



Fowmy_0-1624626497973.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I really appreciate the time you've taken to help and this is way closer than i could have gotten by myself! However, it's still not giving me the expected value. I'm trying to achieve Elapsed_Time_Days_c minus the weekends -

 

expected.JPG

 

Strangely enough the line highlighted in green is calculating correctly!

 

Here's the same but in text form -

 

Entry_Time__cExit_Time__cElapsed_Time_Days__cTurnaround Business DaysTurnaround Business Days 2Expected Values
28/06/2019 09:1004/07/2019 09:336.0251.024.02
05/06/2019 10:0305/06/2019 15:180.221-0.780.22
19/06/2019 08:3519/06/2019 11:110.111-0.890.11
20/06/2019 14:1020/06/2019 15:230.051-0.950.05
05/07/2019 13:2305/07/2019 15:150.081-0.920.08
08/07/2019 15:4015/07/2019 10:186.7860.784.78
09/07/2019 13:4409/07/2019 14:540.051-0.950.05
11/07/2019 08:0522/07/2019 14:1511.2683.267.26
12/07/2019 11:1915/07/2019 09:362.9320.930.93
22/07/2019 13:2522/07/2019 15:420.11-0.90.1
15/07/2019 08:2115/07/2019 11:050.111-0.890.11

 

Thank you!

@lewisgrantevans 

I foud the issue, I set it as TRUE for working day, it should be false:

Turnaround Business Days = 
var __workdays = 
    CALCULATE(
        COUNTROWS('Calendar'),
        DATESBETWEEN(
            'Calendar'[Date],
            'Case Assignment History'[Entry_Time__c],
            'Case Assignment History'[Exit_Time__c] ),
            'Calendar'[IsWorkingDay] = FALSE
    )
var __days = CONVERT('Case Assignment History'[Exit_Time__c]-'Case Assignment History'[Entry_Time__c],DOUBLE)

return
  __days - __workdays

Fowmy_0-1624630245044.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Amazing, thank you very much Sir! Have a great weekend

@lewisgrantevans 

What is your working day definition? Saturday and Sunday ? Do you have any other days not marked as non working days like holidays?

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.