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.
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.
Please let me know what im doing wrong or if there i any other alternatives. Please note im using direct query. Thank you!
Solved! Go to Solution.
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:
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
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:
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
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:
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
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:
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.
Hour = TIMEVALUE( DateTime[Value] ) * 24
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?
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?
@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"
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?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
102 | |
77 | |
68 | |
61 |
User | Count |
---|---|
148 | |
107 | |
106 | |
82 | |
70 |