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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
icdns
Post Patron
Post Patron

Group time of the day

Hello, 

 

I would like to create a grouping for this analysis "What time of the day do customers usually pay their bill?". In my table, I have a transaction date/time column. Now, I would like to group the time by ex. 9AM, 10AM...

 

Example scenario: 

 

FROM: 

Transaction_date_time: 

9/1/2020 9:01 AM

9/1/2020 9:30 AM

9/1/2020 9:45 AM

9/1/2020 10:01 AM

9/1/2020 10:11 AM 

9/1/2020 10:22 AM 

 

TO:

Transaction_date_time: 

9AM

10AM

 

So i could have a analysis per time of the day and show that in a graph. THank you! 🙂 

 

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @icdns 

Download example PBIX file with this query.

First convert the transactions date/times into date time type in Power Query, then convert to time type.  You can then extract the hour and group by this to get what you want.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WstQ31DcyMDJQsLQyMFRw9FWK1UERNDbAImhiiiFoaIBNP1DUECSqgCFsZARWHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction_date_time: " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Transaction_date_time: ", type datetime}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Transaction_date_time: ", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Time.Hour([#"Transaction_date_time: "])),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Time of Day", each Time.From(#time([Custom],0,0))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"})
in
    #"Removed Columns"

 

grouped-time.png

regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

v-yuaj-msft
Community Support
Community Support

Hi @icdns ,

 

Based on your description, you can create a column or just modify the original date/time column as follows.

Transaction_time = FORMAT('Sheet4'[Transaction_date_time],"h AM/PM")
 
Result:
 

v-yuaj-msft_0-1608531131650.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yuaj-msft
Community Support
Community Support

Hi @icdns ,

 

Based on your description, you can create a column or just modify the original date/time column as follows.

Transaction_time = FORMAT('Sheet4'[Transaction_date_time],"h AM/PM")
 
Result:
 

v-yuaj-msft_0-1608531131650.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello! 

 

This one worked! However, can i order my axis? Please see image below. 

 

ex. 8AM, 9AM 10AM, 11AM,12PM, 1PM, 2PM 3PM...

 

icdns_0-1609914766264.png

 

Thanks! 

 

 

Regards,

Inna

Hi @icdns ,

 

You can do some steps as follows:

1. create a column.

 

Column 4 =
var x1=HOUR('Sheet4 (2)'[Transaction_date_time])
return
IF(x1=0,x1+12,x1)
 
2. sort "Transaction_date_time" column by "column 4".

v-yuaj-msft_0-1609920643230.png

Result:

v-yuaj-msft_1-1609920682211.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@icdns , You can create a time table and join with that

https://kohera.be/blog/power-bi/how-to-create-a-time-table-in-power-bi-in-a-few-simple-steps/

 

Separate date and time and join with Date and Time table 

 

date = [Transaction_date_time].date

time =[Transaction_date_time].time

 

PhilipTreacy
Super User
Super User

Hi @icdns 

Download example PBIX file with this query.

First convert the transactions date/times into date time type in Power Query, then convert to time type.  You can then extract the hour and group by this to get what you want.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WstQ31DcyMDJQsLQyMFRw9FWK1UERNDbAImhiiiFoaIBNP1DUECSqgCFsZARWHAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction_date_time: " = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Transaction_date_time: ", type datetime}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Transaction_date_time: ", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Time.Hour([#"Transaction_date_time: "])),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Time of Day", each Time.From(#time([Custom],0,0))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom"})
in
    #"Removed Columns"

 

grouped-time.png

regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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