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

Shifted Start Date with Year to Date Since Inception

Hi all,

I'm new to Power BI and am trying to transform date data (sourced from SQL Server) according to the shift scheme we use. For propery reporting to my users, I need to determine which shift data falls into, and usually only report data for the current shift. The logic below has worked for me in SQL but I am pretty lost in where to begin with Power BI. I don't see how I can use the standard features of columns with "IF" kind of logic. Can anyone point me in the right direction?

 

>If the timestamp's hour is midnight through 3am, then the shift date is "date - 1" (2nd shift runs 6pm - 3am so Wednesday 2am is really part of Tuesday 2nd shift)

>If the hour is 6am - 5pm, then shift = 1st. If the hour is 6pm - 3am, then shift = 2nd.

>If the timestamp is within the last 8 hours & the shift = shift determined from current time, then current shift = true.

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

Hi @Anonymous ,

I share a sample measure formula to mark your shift date and index, you can try it if it works on your side:

Shift Index =
VAR _currDate =
    MAX ( Table[timestamp] )
VAR _shiftIndex =
    IF ( HOUR ( _currDate ) >= 6 && HOUR ( _currDate ) <= 17, "1st", "2nd" )
VAR _shitfDate =
    IF ( HOUR ( _currDate ) <= 3, _currDate - 1, _currDate )
RETURN
    _shitfDate & " " & _shiftIndex

I'm not so clarify for your condition #3, can you please explain more about this?
In addition, if above not help, please provide some sample data to help us clarify your data structure and test to coding formula.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @Anonymous ,

I share a sample measure formula to mark your shift date and index, you can try it if it works on your side:

Shift Index =
VAR _currDate =
    MAX ( Table[timestamp] )
VAR _shiftIndex =
    IF ( HOUR ( _currDate ) >= 6 && HOUR ( _currDate ) <= 17, "1st", "2nd" )
VAR _shitfDate =
    IF ( HOUR ( _currDate ) <= 3, _currDate - 1, _currDate )
RETURN
    _shitfDate & " " & _shiftIndex

I'm not so clarify for your condition #3, can you please explain more about this?
In addition, if above not help, please provide some sample data to help us clarify your data structure and test to coding formula.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.