cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
moshe_Arama2022
Frequent Visitor

- Help - covert excel formula to power query - CONVERT TIME TO SHIFT NAME

Hi !

how can i make function like excel in the power query
the excel function is :
=IF(AND(U3>=TIME(6,0,0),U3<=TIME(15,0,0)),"Morning",IF(AND(U3>=TIME(15,1,0),U3<=TIME(23,0,0)),"Evening",
"Night"))
U3 = COLUMN with time_for_shift_segmentation LIKE 10:59:00 I mean, based on the time, I want to know which shift it belongs.

 

CONVERT TIME TO SHIFT EXCEL.PNG

1 ACCEPTED SOLUTION

You can copy the logic from my previous reply after the each-expression in the formula bar of that step

if [time_for_shift_segmentation] >= #time(6, 0, 0) and [time_for_shift_segmentation] < #time(15, 0, 0) then "Morning" else if [time_for_shift_segmentation] >= #time(15, 0, 0) and [time_for_shift_segmentation] < #time(23, 0, 0) then "Evening" else "Night"

 

Make sure to keep the closing parenthesis of the Table.AddColumn function.

Ps. If this helps solve your query please mark this post as Solution, thanks!

View solution in original post

3 REPLIES 3
m_dekorte
Super User
Super User

Hi @moshe_Arama2022,

 

You can add a conditional column for that. Note that above you'd included that both start and end time in a Shift therefore 15:00 would belong to Morning not Evening, I adjusted that below but you can change that of course.

 

Give something like this a go

AddShift = Table.AddColumn( PrevStepNameHere, "Custom", each 
      if [time_for_shift_segmentation] >= #time(6, 0, 0) and [time_for_shift_segmentation] < #time(15, 0, 0) then "Morning"
      else if [time_for_shift_segmentation] >= #time(15, 0, 0) and [time_for_shift_segmentation] < #time(23, 0, 0) then "Evening"
      else "Night", 
    type text
  )

 

hi thank you ! 

its helps me 

bay the way i have tried to use in conditional column but i didnt get what i need 

 

moshe_Arama2022_0-1682401279381.png

 

You can copy the logic from my previous reply after the each-expression in the formula bar of that step

if [time_for_shift_segmentation] >= #time(6, 0, 0) and [time_for_shift_segmentation] < #time(15, 0, 0) then "Morning" else if [time_for_shift_segmentation] >= #time(15, 0, 0) and [time_for_shift_segmentation] < #time(23, 0, 0) then "Evening" else "Night"

 

Make sure to keep the closing parenthesis of the Table.AddColumn function.

Ps. If this helps solve your query please mark this post as Solution, thanks!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors