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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
boa
Helper I
Helper I

Time.FromText gives sometimes an error

Hello

I'm new to PowerQuery. I have a simple question.

I want to change a column with the time in (format is text) to a time format. I used "Time.FromText"-function in PowerQuery. This is not always working. How do I have to change the text format of the time column so that it displays also the 0 in the begin.

(625 --> 0625). Is there a function for?

 

boa_1-1668077662784.png

Greetings

 

1 ACCEPTED SOLUTION
AntrikshSharma
Community Champion
Community Champion

@boa You can use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText (
                        "i45WMjQ2NlaK1QEyLEwNwQwDMyNTMMPSwABMm0IoIwMo3xCkIxYA",
                        BinaryEncoding.Base64
                    ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ Time = _t ]
        ),
    AddedCustom = 
        Table.AddColumn (
            Source,
            "Custom",
            each 
            Time.FromText ( 
                Text.PadStart ( [Time], 4, "0" ) 
            ),
            Time.Type
        )
in
    AddedCustom

View solution in original post

3 REPLIES 3
AntrikshSharma
Community Champion
Community Champion

@boa You can use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText (
                        "i45WMjQ2NlaK1QEyLEwNwQwDMyNTMMPSwABMm0IoIwMo3xCkIxYA",
                        BinaryEncoding.Base64
                    ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ Time = _t ]
        ),
    AddedCustom = 
        Table.AddColumn (
            Source,
            "Custom",
            each 
            Time.FromText ( 
                Text.PadStart ( [Time], 4, "0" ) 
            ),
            Time.Type
        )
in
    AddedCustom

Thank you for your help. Your syntax is too difficult for me 🤔 but I used a function from it and it works!!

I added a custom column with this function: Text.PadStart ( [Time], 4, "0" ) and then used the function Time.FromText on the added column. So thanks for your help!

@boa My syntax generates the data and fixes the issue, you don't need to use the source step, I wanted to show you how you can apply that on our data, also, I combined the code for 2 columns in just one 😎

 

Since my code was useful in resolving the problem, please mark it as a solution so that others can find it useful as well.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors