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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Format Function isn't accepting DAX custom date/time characters

I have a Date/Time field in this format: "6/13/2017 1:47:00 PM"

 

I want to create a new column that displays in this format: "1pm"

 

The DAX function reference for Format suggests that the way to do it would be with the format string "htt", so my function looks like this:

 

Hour Created = FORMAT('DataTable'[Created DateTime], "htt")

But it doesn't recognize "tt" and instead of "1PM", it returns "13tt". Won't take "t" either. Also, in testing, it doesn't respect "gg", "z", "zz", or "zzz". It also treats minute characters "m" and "mm" the same as month characters "M" and "MM" (so not sure how you would isolate minutes), "y" displays the numeric day of the year, and "yyy" seems to display number of days since June 1970.

 

Is there a different reference sheet for the Format function as it is used in Power BI?

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

To get hour in format "1PM", please try below formula:

Hour Created = FORMAT('DataTable'[Created DateTime], "h AM/PM")

Also, using AM/PM, am/pm, A/P, a/p can return expected result.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

2 REPLIES 2
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

To get hour in format "1PM", please try below formula:

Hour Created = FORMAT('DataTable'[Created DateTime], "h AM/PM")

Also, using AM/PM, am/pm, A/P, a/p can return expected result.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

That did that trick. Where did you find it? Is there a better reference for the Power BI Format function? What would you use for minutes, since both lower and upper-case m and mm refer to month? 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.