cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.

1 ACCEPTED SOLUTION
Community Support

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()
)
)``````

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.
7 REPLIES 7
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()
)
)``````

Community Support

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()
)
)``````

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.
New Member

It's working. Thanks.

Super User

What is the existing relationship column between these two tables?

Thanks,

Proud to be a Super User!

Super User

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,

Proud to be a Super User!

New Member

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

Super User

Ok. Will come back

Proud to be a Super User!

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.