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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
slcekala77
New Member

Show milliseconds from data source with Power Query

Hi,

I'm using PowerQuery to import data that has a time column with the data in this format (as shown in the editor when I select a cell in that column):
19:56:40.0560000 (7:56:40 pm with 56 milliseconds)

 

I want to be able to view the data in that format within PowerQuery.

 

I have searched this community but I haven't found this exact scenario, and I'm new enough that I can't easily extrapolate what I was reading for close but not quite this case to my situation.

 

Thanks in advance for any help.

7 REPLIES 7
ThxAlot
Super User
Super User

That's a recognisable format of native data type of time; Time.From() does the trick.

ThxAlot_0-1698009253701.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



That is not available in Power Query; only in Power BI

Thanks for the suggestion.  But Time.From([Timestamp]) yields the same result - it displays without the milliseconds and I'm trying to get it to display in the power query cells with milliseconds.  Ultimately I'll be doing math with those milliseconds.

 

slcekala77_0-1698017052529.png

 

I think you are presenting an XY problem.

 

Doing the math has nothing to do with the format you see in the Power Query cell. Using the duration type will allow you  to see the milliseconds. Using the time type will not. But in either case, the milliseconds will be preserved in the value stored, so there should be no problem doing math.

 

If you need to see it exactly as you show for some reason, then give it a text type and just use the appropriate conversion functions when you do the math.

Thanks for the reply. I do understand that the values will be preserved in the data.  I'm trying to get all the way through PQ before dabbling in PowerBI, so I'll keep in mind that this is possible in PowerBI and look at that sooner than I otherwise might have.  I'll also take a closer look at the duration type.

 

I'm transitioning this data from a in-worksheet dataset where one of the things I'm computing is the difference in milliseconds between rows to identify those records where the difference is over (for example) 2 milliseconds.  But I'm having trouble understanding what to do where and I may be too focused on what it looks like in PQ for the moment 🙂

Here's an example showing the difference in milliseconds between two values, and also demonstrating that even with the time type, the result is proper. You could also use the duration type, but both columns should be the same data type.

 

let
   Source = #table(type table[Time1=text, Time2=text],{{"19:56:40.0560000", "19:56:40.0920000"}}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time1", type time}, {"Time2", type duration}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Milliseconds Difference", 
            each Duration.Seconds([Time2]-[Time1])*1000, type number)
in
    #"Added Custom"

 

ronrsnfld_0-1698021294294.png

If you want to leave the data as text type, then you could use the following to get the difference:

 

let
   Source = #table(type table[Time1=text, Time2=text],{{"19:56:40.0560000", "19:56:40.0920000"}}),
    #"Added Custom" = Table.AddColumn(Source, "Milliseconds difference", 
        each Duration.Seconds(Time.From([Time2])- Time.From([Time1])) *1000, type number)
in
    #"Added Custom"

 

ronrsnfld_2-1698021850248.png

 

 

 

 

 

 

ronrsnfld
Super User
Super User

I don't think you can do that precisely.

I don't think Time includes milliseconds.

You can set the text string to a duration type, but you will have a leading 0. representing the number of days.

 

 

let
   Source = #table({"Time"}, {{"19:56:40.0560000"}}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type duration}})
in
    #"Changed Type"

 

 

ronrsnfld_0-1697978336422.png

 

 

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors