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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Adamplau
New Member

Calculate when start production (excluding weekends)

Hi Guys,
I would like to callculate when I should start production, excluding weekends.
I have two tables Date (mater calendar) and Orders (with [ProductionDueDate] and [ProdactionDurationInDays])
Both tables have inactive Relationship Date[Date] and Orders[ProductionDueDate]

Basicaly, if ProductionDueDate is on Monday and  ProdactionDurationInDays takes 4 business days, I would like to start production on Tuesday week before.

Please help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Adamplau ,

You can update the formula of the calculated column [Prod. Start Date (exc. weekends)] as below in the table 'Orders' and check if it can return your expected result... It is not required to create any relationship between the table 'Orders' and 'Date' table.

Prod. Start Date (exc. weekends) =
VAR DateIdx =
    CALCULATE (
        MAX ( 'Date'[WorkingDayIndex] ),
        FILTER ( 'Date', 'Date'[Date] = 'Orders'[ProductionDueDate] )
    )
VAR NewDateIdx = DateIdx - 'Orders'[ProdactionDurationInDays]
RETURN
    CALCULATE (
        MAX ( 'Date'[Date] ),
        FILTER (
            ALL ( 'Date' ),
            'Date'[WorkingDayIndex] = NewDateIdx
                && 'Date'[IsWorkingDay] = TRUE()
        )
    )

yingyinr_0-1664185291134.png

Best Regards

View solution in original post

7 REPLIES 7
Adamplau
New Member

I have this working, however I need to have active relationship between Date and Orders tables.
How to change it and activate the relationship in the script using USERELATIONSHIP?

Prod. Start Date (exc. weekends) = 
VAR DateIdx =    
    CALCULATE( 
        MAX( 'Date'[WorkingDayIndex] ),      
        'Orders'[ProductionDueDate] = RELATED('Date'[Date] )
    ) 
VAR NewDateIdx = DateIdx - 'Orders'[ProdactionDurationInDays]

RETURN
CALCULATE(
    MAX('Date'[Date]),
    FILTER(
        ALL('Date'),
        'Date'[WorkingDayIndex] = NewDateIdx 
            && 'Date'[IsWorkingDay] = TRUE()
    )
)

 

Anonymous
Not applicable

Hi @Adamplau ,

You can update the formula of the calculated column [Prod. Start Date (exc. weekends)] as below in the table 'Orders' and check if it can return your expected result... It is not required to create any relationship between the table 'Orders' and 'Date' table.

Prod. Start Date (exc. weekends) =
VAR DateIdx =
    CALCULATE (
        MAX ( 'Date'[WorkingDayIndex] ),
        FILTER ( 'Date', 'Date'[Date] = 'Orders'[ProductionDueDate] )
    )
VAR NewDateIdx = DateIdx - 'Orders'[ProdactionDurationInDays]
RETURN
    CALCULATE (
        MAX ( 'Date'[Date] ),
        FILTER (
            ALL ( 'Date' ),
            'Date'[WorkingDayIndex] = NewDateIdx
                && 'Date'[IsWorkingDay] = TRUE()
        )
    )

yingyinr_0-1664185291134.png

Best Regards

It's working. Thanks.

@Adamplau ,

What is the existing relationship column between these two tables?

Thanks,





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Arul
Super User
Super User

@Adamplau ,

I hope the below query would help you to solve the problem,

 

Starting Day = 
VAR _date =
    SELECTEDVALUE ( 'Table'[ProductionDueDate] )
VAR _duration =
    SELECTEDVALUE ( 'Table'[ProdactionDurationInDays] )
RETURN
    "Start Production on [" & FORMAT ( _date - _duration, "dddd-mmm-d" )&"]"

 

Thanks,





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Sorry, but this not what I need. I need to calculate weekends etc. Please read the description.

Ok. Will come back





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.