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
farhandsome
Helper I
Helper I

Production Data - Throughput Target with various shift times

Hi all,

 

Dealing with a bit of a head scratcher. This is more of a logic based issue rather than actual Power BI code. Hoping someone can help out! Here's the scenario:

 

SiteShift NumberShift Start TimeShift End TimeShift Target
Site A18:00 AM4:00 PM10000
Site B19:00 AM6:00 PM15000
Site B27:00 PM2:00 AM6000
Site C16:00 AM3:00 PM20000

 

This table contains the sites as well as their respective shift times. The master table above is part of an effort in order to capture throughput data from each of the following sites. This master table is connected to tables with a running log of output for each site and shift like so:

 

SiteShift NumberOutputTimestamp
Site A125009:45 AM
Site A1420011:15 AM
Site A1560012:37 PM
Site A175002:15 PM

 

So there is a one-to-many relationship between the master table and these child throughput tables. The goal is to create use a gauge chart with the following metrics:

  • Value: Latest Throughput Value (Latest Output in Child Table)
  • Maximum Value: Throughput Target for the Day (Shift Target in Master Table)
  • Target Value: Time-dependent project target
    i.e. if we are halfway through Site A's shift 1, we should be at 5000 units: (time passed in shift / total shift time) * shift output
    if the shift is currently in non-working hours, then the target value = maximum value

Easy enough, but the problem we are facing is the target value erroring for shifts that cross into the next day (i.e. Site B's shift 2).

The shift times are stored as date-independent time values. Here's the code for the measure to get the target value:

 

 

Var CurrentTime = HOUR(UTCNOW()) * 60 + MINUTE(UTCNOW())
VAR ShiftStart = HOUR(MAX('mtb MasterTableUTC'[ShiftStartTimeUTC])) * 60 + MINUTE(MAX('mtb MasterTableUTC'[ShiftStartTimeUTC]))
VAR ShiftEnd = HOUR(MAX('mtb MasterTableUTC'[ShiftEndTimeUTC])) * 60 + MINUTE(MAX('mtb MasterTableUTC'[ShiftEndTimeUTC]))
VAR ShiftDiff = ShiftEnd - ShiftStart

Return
IF(CurrentTime > ShiftEnd || CurrentTime < ShiftStart, MAX('mtb MasterTableUTC'[OutputTarget]),  
      ( (CurrentTime - ShiftStart) / ShiftDiff) * MAX('mtb MasterTableUTC'[OutputTarget]))

 

 

Basically, if the current time is outside the range of the shift, it should have the target value equal the total shift target, but if it is in the shift time, it calculates it as a ratio of time passed within the shift. This does not work with shifts that cross midnight as the shift end time value is technically earlier than the shift start time value. Any ideas on how to modify the measure to account for these shifts?

2 REPLIES 2
AllisonKennedy
Super User
Super User

@farhandsome Are the shift times well defined as only the examples in your table above? It could possibly be done with lots of IF statements (or a SWITCH??) 

 

Would be easier if you have Date - is there Date columns in both tables that you can combine? Or even if only in the timestamp table, then you can convert the shifts one using dummy dates?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@llucasll1 

 

Hi Allison,

 

Thank you for the response. Unfortunately, the master table above is just an example - there's over 10 sites with multiple shifts each and that could grow, so I'd need a more modular approach rather than using a host of nested if's.

 

Could you explain how attaching a date would work? For example, a shift of 6pm to 2am would need to have respective dates of [Today] and [Tomorrow], but when the current time passes midnight, those shift dates would need to change to [Yesterday] and [Today]. Does that make sense?

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.