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
frankhofmans
Helper IV
Helper IV

Add number of working days to a start date

hi PBI experts,

 

i have the following case:

 

We have a KPI for the production time of our products (A, B, C) and regions (Europe, North America, Asia). The production time of product A in region Europe may take 2 working days, weekend days not included. we have a KPI file and a production file:

 

KPI file:

 

Production typeRegionKPI working daysKey
AEurope2A/Europe
ANorth America4A/North America
AAsia3A/Asia
BEurope7B/Europe
BNorth America11B/North America
BAsia9B/Asia
CEurope20C/Europe
CNorth America30C/North America
CAsia27C/Asia

 

Production file:

 

Product typeRegionDate Start ProductionWeekdayKPIDate End Production
AEurope3-1-2020Friday26-1-2020
ANorth America1-1-2020Wednesday46-1-2020
AAsia7-1-2020Tuesday39-1-2020
BEurope9-1-2020Thirsday313-1-2020
BNorth America5-1-2020Sunday510-1-2020
BAsia5-3-2020Thirsday410-3-2020
CEurope27-2-2020Thirsday43-3-2020
CNorth America1-4-2020Wednesday68-4-2020
CAsia3-4-2020Friday59-4-2020
AEurope10-4-2020Friday213-4-2020
ANorth America20-4-2020Monday423-4-2020
AAsia3-5-2020Sunday36-5-2020
BEurope7-5-2020Thirsday311-5-2020
BNorth America13-5-2020Wednesday519-5-2020
BAsia5-6-2020Friday410-6-2020
CEurope11-6-2020Thirsday416-6-2020
CNorth America20-6-2020Saturday629-6-2020
CAsia30-6-2020Tuesday56-7-2020
AEurope1-7-2020Wednesday22-7-2020
ANorth America10-7-2020Friday415-7-2020
AAsia13-7-2020Monday315-7-2020
BEurope15-6-2020Monday317-6-2020
BNorth America1-7-2020Wednesday57-7-2020
BAsia1-8-2020Saturday35-8-2020
CEurope10-8-2020Monday413-8-2020
CNorth America20-8-2020Thirsday627-8-2020
CAsia3-8-2020Monday57-8-2020

 

The column date end production is the needed outcome (start date + KPI working days). If the production of type A in Europa starts on monday, the production has to be finished on tuesday. If the production starts on saturday, the production also has to be finished on tuesday. 

 

I hope someone can help me with this problem.

 

Thanks in advance,

 

Regards, Frank

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @frankhofmans ,

 

I referred to the link posted by @amitchandak .

1.Create a calendar table.

 

Date = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 8, 28 ) ),
    "Work Day", IF ( WEEKDAY ( [Date], 2 ) >= 6, 0, 1 ),
    "Work Date", IF ( WEEKDAY ( [Date], 2 ) >= 6, BLANK (), [Date] )
)
Work Date Cont =
IF (
    [Work Day] = 0,
    MAXX (
        FILTER (
            'Date',
            [Date] < EARLIER ( [Date] )
                && [Work Day] <> EARLIER ( [Work Day] )
        ),
        [Date]
    ),
    [Date]
)
Work Date cont Rank =
RANKX ( ALL ( 'Date' ), [Work Date Cont],, ASC, DENSE )

 

1.png

 

2.Create a calculated column.

 

DateEndProduction = 
VAR _rank =
    RELATED ( 'Date'[Work Date cont Rank])
VAR _kpi = 'Production'[KPI]
RETURN
    SWITCH (
        TRUE (),
        WEEKDAY ( 'Production'[Date Start Production], 2 ) = 6
            || WEEKDAY ( 'Production'[Date Start Production], 2 ) = 7,
            CALCULATE (
                MIN ( 'Date'[Date] ),
                FILTER ( ALL ( 'Date' ), 'Date'[Work Date cont Rank] = _rank + _kpi )
            ),
        WEEKDAY ( 'Production'[Date Start Production], 2 ) <= 5,
            CALCULATE (
                MIN ( 'Date'[Date] ),
                FILTER ( ALL ( 'Date' ), 'Date'[Work Date cont Rank] = _rank + _kpi - 1 )
            )
    )

 

2.png

 

You can check more details from here.

 

 

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @frankhofmans ,

 

I referred to the link posted by @amitchandak .

1.Create a calendar table.

 

Date = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2020, 8, 28 ) ),
    "Work Day", IF ( WEEKDAY ( [Date], 2 ) >= 6, 0, 1 ),
    "Work Date", IF ( WEEKDAY ( [Date], 2 ) >= 6, BLANK (), [Date] )
)
Work Date Cont =
IF (
    [Work Day] = 0,
    MAXX (
        FILTER (
            'Date',
            [Date] < EARLIER ( [Date] )
                && [Work Day] <> EARLIER ( [Work Day] )
        ),
        [Date]
    ),
    [Date]
)
Work Date cont Rank =
RANKX ( ALL ( 'Date' ), [Work Date Cont],, ASC, DENSE )

 

1.png

 

2.Create a calculated column.

 

DateEndProduction = 
VAR _rank =
    RELATED ( 'Date'[Work Date cont Rank])
VAR _kpi = 'Production'[KPI]
RETURN
    SWITCH (
        TRUE (),
        WEEKDAY ( 'Production'[Date Start Production], 2 ) = 6
            || WEEKDAY ( 'Production'[Date Start Production], 2 ) = 7,
            CALCULATE (
                MIN ( 'Date'[Date] ),
                FILTER ( ALL ( 'Date' ), 'Date'[Work Date cont Rank] = _rank + _kpi )
            ),
        WEEKDAY ( 'Production'[Date Start Production], 2 ) <= 5,
            CALCULATE (
                MIN ( 'Date'[Date] ),
                FILTER ( ALL ( 'Date' ), 'Date'[Work Date cont Rank] = _rank + _kpi - 1 )
            )
    )

 

2.png

 

You can check more details from here.

 

 

 

Best Regards,

Stephen Tao

 

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

Many thanks Stephen! This works perfect.

 

Regards,

 

Frank

amitchandak
Super User
Super User

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.