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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RKM
Helper IV
Helper IV

How to get a calculated TIMEKEY Column HHMM on Table DirectQuery Mode

I hope this should super simple but I'm new to PowerBI and feeling clueless.

I am accessing Data From a View in DirectQuery where there is a DateTime Column 'StartTime' and I need to be able to add relationship with this to my TimeDimension having TimeKey field in HHMM  (Integer). 

Therefore I tried creating a calculated column from my StartTime column.

 

But I just couldn't figure out how to do so. Format funtion doesn't work. Not sure what else actually works. I guess what I need would be somewhat like,

 

Right("0" + Time.Hour(StartTime), 2) + Right("0" + Time.Minute(StartTime), 2)

I also tried

= Table.AddColumn(dbo_vw_log, "StartTimeKey", each Time.ToText([StartTime], "HHmm"), type text)

~ Here also DirectQuery not supporting above

 

But then RIGHT also doesn't work. Please can someone help?

1 ACCEPTED SOLUTION
RKM
Helper IV
Helper IV

Finally Managed to figure out something.. If at all it helps for anyone..

 

=Table.AddColumn(dbo_VW_LOG, "START_TIMEKEY", each Text.End("00" & Text.From(Time.Hour([STARTTIME])), 2) & Text.End("00" & Text.From(Time.Minute([STARTTIME])), 2))

View solution in original post

4 REPLIES 4
RKM
Helper IV
Helper IV

Finally Managed to figure out something.. If at all it helps for anyone..

 

=Table.AddColumn(dbo_VW_LOG, "START_TIMEKEY", each Text.End("00" & Text.From(Time.Hour([STARTTIME])), 2) & Text.End("00" & Text.From(Time.Minute([STARTTIME])), 2))

mahoneypat
Microsoft Employee
Microsoft Employee

You can try it as a DAX column with

 

HHMM = FORMAT(DateTime[StartDate], "HHMM")

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Greg_Deckler
Super User
Super User

@RKM - Perhaps use Text.End instead of Right?

Text.End - PowerQuery M | Microsoft Docs

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for your suggestion. But no luck with Text.End as well. It didn't work

 

Capture.JPG

 

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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