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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Dax Help - Column to determine if date time within shift hours

Hi there

 

I have a fact table with a date time field and dimension table with the shift type.

I need to calculate, based on the shift being undertaken, whether an interaction occured within the shift hours or outside the shift hours. 

 

The shift start and end times are columns in any table.

 

 

Table1(ShiftType) = "Afternoon"

Shift Times are 12:30pm to 11:30pm

 

Table1(ShiftType) = "Day"

Shift times are 08:30am to 16:30pm

 

I'm trying to calculate whether Table2(InteractionDateTime) has occured outside those hours for the relevant shift. 

Any advice? 

 

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Please follow the steps below.

 

1. Create two calculated columns in Table 1.

 

 

starttime = IF('Table1'[ShiftType]="Afternoon",TIME(12,30,00),IF('Table1'[ShiftType]="Day",TIME(8,30,00)))

endtime = IF('Table1'[ShiftType]="Afternoon",TIME(23,30,00),IF('Table1'[ShiftType]="Day",TIME(16,30,00)))

2. Create the calculated column in Table 2.

 

 

Column 2 =
IF (
    AND (
        TIMEVALUE ( 'Table2'[InteractionDateTime] )
            >= TIMEVALUE ( RELATED ( Table1[starttime] ) ),
        TIMEVALUE ( 'Table2'[InteractionDateTime] )
            <= TIMEVALUE ( RELATED ( 'Table1'[endtime] ) )
    ),
    1,
    0
)

Here is the output.

 

output.PNG

More details, you could refer to the attacement below.

 

If you still need help, could you share your desired output so that we could help further on it?

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
LivioLanzo
Solution Sage
Solution Sage

Hi @Anonymous

 

would you be able to past a sample of your two tables?

 

thank you

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Yep sure @LivioLanzo

Table2

IDInteractionDateTime
P118/09/2018 22:40
P217/09/2018 15:20
P31/09/2018 3:40
P41/09/2018 22:20
P51/09/2018 8:00
P61/09/2018 17:30

 

Table1

IDShiftType
P1Afternoon
P2Day
P3Afternoon
P4Afternoon
P5Afternoon
P6

Day

Hi @Anonymous,

 

Please follow the steps below.

 

1. Create two calculated columns in Table 1.

 

 

starttime = IF('Table1'[ShiftType]="Afternoon",TIME(12,30,00),IF('Table1'[ShiftType]="Day",TIME(8,30,00)))

endtime = IF('Table1'[ShiftType]="Afternoon",TIME(23,30,00),IF('Table1'[ShiftType]="Day",TIME(16,30,00)))

2. Create the calculated column in Table 2.

 

 

Column 2 =
IF (
    AND (
        TIMEVALUE ( 'Table2'[InteractionDateTime] )
            >= TIMEVALUE ( RELATED ( Table1[starttime] ) ),
        TIMEVALUE ( 'Table2'[InteractionDateTime] )
            <= TIMEVALUE ( RELATED ( 'Table1'[endtime] ) )
    ),
    1,
    0
)

Here is the output.

 

output.PNG

More details, you could refer to the attacement below.

 

If you still need help, could you share your desired output so that we could help further on it?

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Worked really well. Thanks heaps!

Helpful resources

Announcements
Europe Fabric Conference

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.