cancel
Showing results for 
Search instead for 
Did you mean: 
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

v-yuaj-msft
Community Support
Community Support

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

 



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!
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
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors