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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Create a new column for shift based on datetime column and time from another tab

Hi everyone,

 

I'm still new to PowerBI and I got a task to create a dashboard from excel data. I got 2 sheets from an excel that I already import to PowerBI.
Machine.jpgShift.jpgTable Machine Shift.jpg

I want to create a column in the Machine_schedule tab that shows the Date and in what shift,

like 2021-07-01 1 or 2021-07-01 2. The 1 2 or 3 are the shift. I already search for some solutions in this forum but still can't find the best way to do this. I still need to learn more about PowerBI for sure.

So is there a way so I can get this done from Power Query? or is it possible to do?

Thank you.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

You can add a new column to your Machine table as follows:

Column = 
VAR _S = TIME(HOUR(Machine[Start]),MINUTE(Machine[Start]),0)
VAR _E = TIME(HOUR(Machine[End]),MINUTE(Machine[End]),0)
RETURN
MAXX(
    FILTER(
        Shift,
        Shift[Start] >= _S && Shift[End] <= _E 
    ),
    Shift[Shift]
)


File attached below my signature:

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@Anonymous 

You can add a new column to your Machine table as follows:

Column = 
VAR _S = TIME(HOUR(Machine[Start]),MINUTE(Machine[Start]),0)
VAR _E = TIME(HOUR(Machine[End]),MINUTE(Machine[End]),0)
RETURN
MAXX(
    FILTER(
        Shift,
        Shift[Start] >= _S && Shift[End] <= _E 
    ),
    Shift[Shift]
)


File attached below my signature:

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hello @Fowmy 
Thank you for your reply.

I just try the solution you give, but I got a blank result. Did I do something wrong?

 

jonathangabe_0-1634013330003.png


I'm trying to do this from Power Query Editor but I can't find a way to compare the DateTime from tab Machine_Schedule to Shift tab, this might be a different topic from what I ask here. 

@Anonymous 

Can you share some dummy data in Power BI file.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy 
I did fix the reason why the result is blank, but some are blank and the rest are just 3. 

jonathangabe_0-1634019391723.png


I can't upload the pbix here. It says pbix is not supported

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors