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
Matt_Mohawk
Helper II
Helper II

Number of Days Calculation

I am trying to figure out an issue with a formula that I have created. I am needing to modify this formula to add an extra day to the "DATE IN" field but ignore dates that have the same "DATE IN" and "DATE OUT". Here is the formula that I am currently using:

 

# of Days =
VAR DateOutBlank = IF(ISBLANK(MJS_PRICE_PW[DATE OUT]),0,MJS_PRICE_PW[DATE OUT])
RETURN CALCULATE(SUM('Date'[Workday Not Holiday]),FILTER(MJS_PRICE_PW,IF(MJS_PRICE_PW[DATE IN]=MJS_PRICE_PW[DATE OUT],1)),DATESBETWEEN('Date'[Date],MJS_PRICE_PW[DATE IN],DateOutBlank))

1 ACCEPTED SOLUTION

Hi @Matt_Mohawk ,

Please try to update the formula of your calculated column [# of days] as below:

# of Days = 
VAR _days =
    CALCULATE (
        SUM ( 'Date'[Workday Not Holiday] ),
        DATESBETWEEN ( 'Date'[Date], MJS_PRICE_PW[DATE IN], MJS_PRICE_PW[DATE OUT] )
    )
RETURN
    IF (
        ISBLANK ( MJS_PRICE_PW[DATE OUT] ),
        BLANK (),
        IF (
            MJS_PRICE_PW[DATE IN] = MJS_PRICE_PW[DATE OUT],
            1,
            _days
                - IF ( NOT ( WEEKDAY ( MJS_PRICE_PW[DATE IN], 1 ) IN { 1, 7 } ), 1, 0 )
        )
    )

yingyinr_1-1614936608526.png

Best Regards

Community Support Team _ Rena
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

7 REPLIES 7
Matt_Mohawk
Helper II
Helper II

@amitchandak thank you for that formula. I am getting the error, "The start date in Calendar function can not be later than the end date."

I am working with some projects that do not have a "DATE OUT" entered yet. Could this be the cause of that problem? That is the main reason why I had the VAR DATEOUTBLANK in my formula before.

@Matt_Mohawk , add an if on top of it and check if it works. or share small sample with expected output

Below is an example of what I am needing. The areas marked in red show that right now it is counting as 2 days, this is actually supposed to be 1 day because we do not count the day that it comes into us. The green area is the area that I want the formula to ignore because if a project comes in and goes out on the same day, it needs to be counted as 1 day. Hope this makes sense.

 

Screen Shot 2021-03-03 at 1.29.05 PM.png

Hi @Matt_Mohawk ,

Please try to update the formula of your calculated column [# of days] as below:

# of Days = 
VAR _days =
    CALCULATE (
        SUM ( 'Date'[Workday Not Holiday] ),
        DATESBETWEEN ( 'Date'[Date], MJS_PRICE_PW[DATE IN], MJS_PRICE_PW[DATE OUT] )
    )
RETURN
    IF (
        ISBLANK ( MJS_PRICE_PW[DATE OUT] ),
        BLANK (),
        IF (
            MJS_PRICE_PW[DATE IN] = MJS_PRICE_PW[DATE OUT],
            1,
            _days
                - IF ( NOT ( WEEKDAY ( MJS_PRICE_PW[DATE IN], 1 ) IN { 1, 7 } ), 1, 0 )
        )
    )

yingyinr_1-1614936608526.png

Best Regards

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

@v-yiruan-msft That did it! You are a lifesaver! Now I only have to figure out how you got it to work so I can learn to do this for later jobs.

Hi @amitchandak,

 

I was wondering if you have any updates for me?

amitchandak
Super User
Super User

@Matt_Mohawk , You can working days like

 

example measure 

Work Day = COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Min(Table[Start Date]),Max(Table[End Date])),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

example column

Work Day = COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(Table[Start Date],Table[End Date]),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

 

Also check 2nd page for workday date diff attcahed file using date table

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.