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
Anonymous
Not applicable

Calendar Table for a busines that operates two shifts in a day

Hi Gurus,

I am going to start off by creating my date table and would like to know that if my company operates two production shifts per day (6pm to 6am next and second shift is from 6am to 6pm same day), is it advisable to do my dates column in the date table also start from 6pm and ending 6 pm the next day OR doing a standard date column from 12 am midnight to 12 pm noon will better suit.

 

Most of the analysis will be done on shifts like last two shifts average production or last 14 shifts average for example.  What type if date column (6am to 6am or 12am to 12am) is best?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Your data table should join either shift start or sift end date.

But you can have shift table with at and shift Number or start time

 

Date , Shift No

 

Now you can have rank on this combination

Date Shift no = Format([Date], "YYYYMMDD")  & [Shift No]

 

Shift Rank = rankx(Shift, [Dare Shift No],,asc, dense)

 

This Shift = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Shift'[Shift Rank]=max('Date'[Shift Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Date'[Shift Rank]=max('Date'[Shift Rank])-1))

 

Last 8 Shift = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Date'[Shift Rank]>=max('Date'[Shift Rank])-8 && 'Date'[Shift Rank]<=max('Date'[Shift Rank])))

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thanks, I already have a date table from 01/07/21 to 30/06/22, how can I create shift rank in that table instead of creating an additional table through the query you provided above?

 

Also where the following column will be created ? In fact table or in date table?

Date Shift no = Format([Date], "YYYYMMDD")  & [Shift No]

 

sorry for asking too many questions.

Thanks in advance.

Anonymous
Not applicable

@amitchandak That's awesome mate. I have been reading your replies and impressed with the way you help the community. Thank you for that.

And yes, my date table is linked with shift end date so that when I select let's say 8th of December from the calendar table I get both the shifts filtered as well (shift that ends on 6am on 8th Dec and shift that ends on 6pm on 8th Dec as well)

Just one more question, in one of my matrix visual I filter the data by last operated shift and I get the required results because most if the measures work with just one shift selected.

However, when on the same matrix I want to have average of last two shifts for yesterday I don't get it with just last shift selected on filters. However when I select full day that is 8th of December then I get the average of two shifts but then my other numbers get wrong. This is spinning my head. 

How can I have the two shifts measures added to the matrix where most of the measures are set on the basis of just last shift selection.

amitchandak
Super User
Super User

@Anonymous , Your data table should join either shift start or sift end date.

But you can have shift table with at and shift Number or start time

 

Date , Shift No

 

Now you can have rank on this combination

Date Shift no = Format([Date], "YYYYMMDD")  & [Shift No]

 

Shift Rank = rankx(Shift, [Dare Shift No],,asc, dense)

 

This Shift = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Shift'[Shift Rank]=max('Date'[Shift Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Date'[Shift Rank]=max('Date'[Shift Rank])-1))

 

Last 8 Shift = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Shift'),'Date'[Shift Rank]>=max('Date'[Shift Rank])-8 && 'Date'[Shift Rank]<=max('Date'[Shift Rank])))

 

 

Anonymous
Not applicable

Thanks @amitchandak , how do I add shift No column in the table? Can you please help by giving me the dax for it

Thanks,

@Anonymous ,

 

In main table

shift no column = If(hour([Datetime]) >=6 && hour([Datetime]) <18 , 1,2)

 

 

Date table with shift

DateShift Table = crossjoin(Calendar(date(2018,01,01), date(2021,12,31)) , union(row("Shift",1) ,row("Shift",2)))

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.