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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jmars
New Member

How to group time into 2

Hello everyone,

I am relatively new to Power Query and have encountered a problem that requires assistance from experienced users.

 

I have datasets where I need to group time into two categories.

 

Category 1: 12:00 AM to 03:00 PM

Category 2: 03:01 PM to 11:59 PM

 

How can I achieve this?

 

Any help would be greatly appreciated.

Thank you.

1 ACCEPTED SOLUTION
Dhairya
Solution Supplier
Solution Supplier

Hey @jmars 

Method 1: Using DAX (calculated column)

I tried creating your scenario and took the below data as input

Input Table:

Dhairya_0-1691582603645.png

 

Please follow the below steps to get your expected output:

Step 1: Created a calculated column using the below code

time = FORMAT(TableTime[date], "hh:nn")

You will get the output below

Dhairya_1-1691582873995.png

Step 2: Created a new calculated column to split your date into expected category

Category = 
IF(
    TableTime[time] >= TIME(00,00,00) && TableTime[time] <= TIME(15,00,00),
    "Category 1",
    "Category 2"
)

You will get the output below

Dhairya_4-1691583069142.png



 

Method 2: Using Power Query

Input Table:

Dhairya_0-1691584356015.png


Please follow the below steps to get your expected output:

Step 1:  Create a Time column from the transform tab as shown below

Dhairya_2-1691584731032.png

 

Step 2:  Now create a custom column using the below code as shown in screenshot

if 
[Time] >= #time(00,00,00) and
[Time] <= #time(15,00,00)
then "Category 1"
else "Category 2"

Dhairya_3-1691585032283.png


You will get the expected output as below

Dhairya_5-1691585083424.png


Here is the whole Power Query for all transformation

let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMrDUN7DQNzIwMlIwNLIyMAAiBUdfpVgdFCkDQ9xSxlCpAKxShjikTHHqMjS0MrWEScUCAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [date = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"date", type datetime}}),
#"Inserted Time" = Table.AddColumn(#"Changed Type", "Time", each DateTime.Time([date]), type time),
#"Added Custom" = Table.AddColumn(
#"Inserted Time",
"Category",
each
if [Time] >= #time(00, 00, 00) and [Time] <= #time(15, 00, 00) then
"Category 1"
else
"Category 2"
)
in
#"Added Custom"


If this helps you then please mark my solution as accepted so that others can find it quickly while facing a similar issue. Thank You!

View solution in original post

2 REPLIES 2
Dhairya
Solution Supplier
Solution Supplier

Hey @jmars 

Method 1: Using DAX (calculated column)

I tried creating your scenario and took the below data as input

Input Table:

Dhairya_0-1691582603645.png

 

Please follow the below steps to get your expected output:

Step 1: Created a calculated column using the below code

time = FORMAT(TableTime[date], "hh:nn")

You will get the output below

Dhairya_1-1691582873995.png

Step 2: Created a new calculated column to split your date into expected category

Category = 
IF(
    TableTime[time] >= TIME(00,00,00) && TableTime[time] <= TIME(15,00,00),
    "Category 1",
    "Category 2"
)

You will get the output below

Dhairya_4-1691583069142.png



 

Method 2: Using Power Query

Input Table:

Dhairya_0-1691584356015.png


Please follow the below steps to get your expected output:

Step 1:  Create a Time column from the transform tab as shown below

Dhairya_2-1691584731032.png

 

Step 2:  Now create a custom column using the below code as shown in screenshot

if 
[Time] >= #time(00,00,00) and
[Time] <= #time(15,00,00)
then "Category 1"
else "Category 2"

Dhairya_3-1691585032283.png


You will get the expected output as below

Dhairya_5-1691585083424.png


Here is the whole Power Query for all transformation

let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMrDUN7DQNzIwMlIwNLIyMAAiBUdfpVgdFCkDQ9xSxlCpAKxShjikTHHqMjS0MrWEScUCAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [date = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"date", type datetime}}),
#"Inserted Time" = Table.AddColumn(#"Changed Type", "Time", each DateTime.Time([date]), type time),
#"Added Custom" = Table.AddColumn(
#"Inserted Time",
"Category",
each
if [Time] >= #time(00, 00, 00) and [Time] <= #time(15, 00, 00) then
"Category 1"
else
"Category 2"
)
in
#"Added Custom"


If this helps you then please mark my solution as accepted so that others can find it quickly while facing a similar issue. Thank You!

Thank you! It worked as expected!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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