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
Jyo27
Helper II
Helper II

Time range

Hi ,

How to calculate if else statement for  time range ? want to create custom column in power query.

 

Jyo27_0-1671550295472.png

Appreciate your help.

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

Hi @Jyo27 ,

 

Please try:

 

= Table.AddColumn(
Previousstepsname, 
"Custom", 
each if [Time] >= #time(5, 0, 0) and [Time] < #time(12, 0, 0) then "A" 
else if [Time] >= #time(12, 0, 0) and [Time] <= #time(17, 0, 0) then "B" 
else null
)

 

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
v-cgao-msft
Community Support
Community Support

Hi @Jyo27 ,

 

Please try:

 

= Table.AddColumn(
Previousstepsname, 
"Custom", 
each if [Time] >= #time(5, 0, 0) and [Time] < #time(12, 0, 0) then "A" 
else if [Time] >= #time(12, 0, 0) and [Time] <= #time(17, 0, 0) then "B" 
else null
)

 

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

nick_potts
New Member

You could categorize or index each time range then make a calculated column with a switch statement on that index. Or do what @Shaurya recommended if there are only a few cases to consider

Shaurya
Memorable Member
Memorable Member

Hi @Jyo27,

 

Instead of custom formula in Power Query, just create a conditional column in DAX. It's much easier.

 

Column = IF(HOUR('Table'[Date])>=5&&HOUR('Table'[Date])<=12,"A",IF(HOUR('Table'[Date])>12&&HOUR('Table'[Date])<=17,"B",""))

 

Works for you? Mark this post as a solution if it does!
Check out this blog of mine: How to Export Telemetry Data from Azure IoT Central into Power BI

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.