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
atjt217
Helper III
Helper III

Grouping Time by Hour Intervals

Hello, 

I hope someone can tell me how to fix this issue. I'm trying to create a calculated column that show time intervals by hour. What i did is i used add a column by hour on Power Query on CreatedOn filed which resulted to CreatedOn Hour then i used this formula: 

C_CreatedOn = IF(vu_Bi_UnableToFill_2019ToCurrent[CreatedOn Hour]>12, vu_Bi_UnableToFill_2019ToCurrent[CreatedOn Hour]-12&" "&"PM",vu_Bi_UnableToFill_2019ToCurrent[CreatedOn Hour]&" "&"AM")

To add the AM/PM on the hour. The problem is when the time is 12 instead of PM it shows AM. 

 

atjt217_0-1625865953194.png

Please let me know what im doing wrong or if there i any other alternatives. Please note im using direct query. Thank you! 

 

 
 
2 ACCEPTED SOLUTIONS
v-yangliu-msft
Community Support
Community Support

Hi  @atjt217 ,

Here are the steps you can follow:

1. Create calculated column.

C_CreateIOn =
var _1=FORMAT('Table'[CreateIOn],"AM/PM")
var _2=
IF(
    'Table'[CreateIOn Hour]>12,
    'Table'[CreateIOn Hour]-12,
    'Table'[CreateIOn Hour])
return
_2&""&_1

2. Result:

vyangliumsft_0-1626079779898.png

 

Best Regards,

Liu Yang

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

v-yangliu-msft
Community Support
Community Support

Hi  @atjt217 ,

Here are the steps you can follow:

1. Create calculated column.

C_CreateIOn =
SWITCH(
    TRUE(),
    'Table'[CreateIOn Hour]>12,'Table'[CreateIOn Hour]-12&""&"PM",
    'Table'[CreateIOn Hour]=12,'Table'[CreateIOn Hour]&""&"PM",
    'Table'[CreateIOn Hour]<12,'Table'[CreateIOn Hour]&""&"AM")

2. Result:

vyangliumsft_0-1626222548191.png

 

 

Best Regards,

Liu Yang

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

10 REPLIES 10
v-yangliu-msft
Community Support
Community Support

Hi  @atjt217 ,

Here are the steps you can follow:

1. Create calculated column.

C_CreateIOn =
SWITCH(
    TRUE(),
    'Table'[CreateIOn Hour]>12,'Table'[CreateIOn Hour]-12&""&"PM",
    'Table'[CreateIOn Hour]=12,'Table'[CreateIOn Hour]&""&"PM",
    'Table'[CreateIOn Hour]<12,'Table'[CreateIOn Hour]&""&"AM")

2. Result:

vyangliumsft_0-1626222548191.png

 

 

Best Regards,

Liu Yang

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

Thank you! This one works 

v-yangliu-msft
Community Support
Community Support

Hi  @atjt217 ,

Here are the steps you can follow:

1. Create calculated column.

C_CreateIOn =
var _1=FORMAT('Table'[CreateIOn],"AM/PM")
var _2=
IF(
    'Table'[CreateIOn Hour]>12,
    'Table'[CreateIOn Hour]-12,
    'Table'[CreateIOn Hour])
return
_2&""&_1

2. Result:

vyangliumsft_0-1626079779898.png

 

Best Regards,

Liu Yang

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

Hello Lui, 

I tried it out but im getting na error cause FORMAT is not allowed for direct query. 

 

atjt217_0-1626107266639.png

 

CNENFRNL
Community Champion
Community Champion

Hour = TIMEVALUE( DateTime[Value] ) * 24

Screenshot 2021-07-10 111756.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hello CNENFRNL,

 

How can i add the AM/PM on the time?

 

CNENFRNL
Community Champion
Community Champion

Hour = FORMAT( DateTime[Value], "HH AM/PM" )

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi CNENFRNL, 

 

I tried this but im getting an error that "FORMAT" is not allowed on direct query Do you have any other options for me? 

AllisonKennedy
Super User
Super User

@atjt217  You can do all of it in Power Query, here's one example that should work:

 

let
StartDate = #datetime(2020,7,1,0,0,0),
EndDate = #datetime(2030,12,31,0,0,0),
DateTime = List.DateTimes(StartDate, Duration.Days(EndDate-StartDate), #duration(0,1,0,0)),
#"Converted to Table" = Table.FromList(DateTime, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "DateTime"}}),
#"Inserted Time" = Table.AddColumn(#"Renamed Columns", "Time", each DateTime.Time([DateTime]), type time),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Inserted Time", "Hour", each Text.BeforeDelimiter(Text.From([Time], "en-US"), ":"), type text),
#"Inserted Last Characters" = Table.AddColumn(#"Inserted Text Before Delimiter", "Last Characters", each Text.End(Text.From([Time], "en-US"), 2), type text)
in
#"Inserted Last Characters"


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hello Allison, 

I tried this out but it switches my table to Import mode and i need this to still be a direct query. Do you have any other options for me? 

atjt217_0-1626107778244.png

 

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.