Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
Hi ,
How to calculate if else statement for time range ? want to create custom column in power query.
Appreciate your help.
Solved! Go to Solution.
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
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
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
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
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 56 | |
| 42 | |
| 41 | |
| 21 | |
| 21 |
| User | Count |
|---|---|
| 150 | |
| 106 | |
| 65 | |
| 36 | |
| 36 |