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
wpf_
Post Prodigy
Post Prodigy

how to convert a whole number to show 12 hour format

Looks like power query M is a complete different beast from DAX.  But I'm trying to create a new column in power query editor because i've been told it's generally better to add there then with DAX.  So I have a column of whole numbers that represent Hours of the day (0-23).  I'm trying to add a new column to convert that to 12 hour format ( 0 = 12:00AM, 13 = 1:00PM etc). Thanks.

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@wpf_ - Not sure who told you that, but it's perhaps true up until the point that it takes 10 times longer to do something than to just do it the way that you know how to do it. But, understood there are some Power Query bigots out there to be sure. But, after all, it ends up being a column in the data model regardless so it's not like it is the end of the world if you do in DAX or Power Query. Anway, you could do it like this in Power Query:

 

Time.FromText([Hour] & ":00:00")

 

Make sure your Hour column is text or you can convert it using Text.From 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@wpf_ - Not sure who told you that, but it's perhaps true up until the point that it takes 10 times longer to do something than to just do it the way that you know how to do it. But, understood there are some Power Query bigots out there to be sure. But, after all, it ends up being a column in the data model regardless so it's not like it is the end of the world if you do in DAX or Power Query. Anway, you could do it like this in Power Query:

 

Time.FromText([Hour] & ":00:00")

 

Make sure your Hour column is text or you can convert it using Text.From 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

Awesome that worked!

Yea I was told by one of the guys on here that power query does a better job of compressing the data.  But it's good to hear that not everyone is on board with that.  I'm already having a hard time wrapping my head around dax, and now M.  : )

@wpf_ - Well, there is one guy in particular but I won't name names. Anyway, in that case, compression has nothing to do with Powre Query or DAX. Compression is in the Vertipaq engine. So, as you can see in the attached PBIX files, 1 was created all in Power Query and 2 was created all in DAX. 2 is actually a tiny amount smaller than 1 so whatever that guy was preaching is bogus IMHO. There are other reasons why you might want to use Power Query over DAX but compression has nothing to do with any of that.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler ,

 

Thanks for that example.  Now I don't have to go crazy scrambling trying to learn M.  

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.