cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Transform lastLogon into date in power query

Hello,

 

I am trying to convert the active directory lastlogon  to readable date and times in power query but I don't find the solution. Could you help me?

 

This is the view.

 

photo query.PNG

Thanks

1 ACCEPTED SOLUTION
Super User III
Super User III

Hello @xavipc_78 

 

you need to devide and subtract something of the lastlogon-number in order to transform it to a DateTimeZone.

each DateTimeZone.From([lastLogon]/ 864000000000 - 109205)

 

Here a complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQxNjQ2tnTVNjRXitWB8o3M4fy80pwchIS5OYpCQwNDVL4FqkGGplgMQjbRyMTUGFkH6XwTIzS+BZp6IwLmEZLHzzc0pK55hP2L7j+S9BsamVjiiRGscWRoaGmCPTkgmU3QrFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [lastLogon = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"lastLogon", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTimeZone.From([lastLogon]/ 864000000000 - 109205))
in
    #"Added Custom"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

View solution in original post

4 REPLIES 4
Super User III
Super User III

Hello @xavipc_78 

 

you need to devide and subtract something of the lastlogon-number in order to transform it to a DateTimeZone.

each DateTimeZone.From([lastLogon]/ 864000000000 - 109205)

 

Here a complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQxNjQ2tnTVNjRXitWB8o3M4fy80pwchIS5OYpCQwNDVL4FqkGGplgMQjbRyMTUGFkH6XwTIzS+BZp6IwLmEZLHzzc0pK55hP2L7j+S9BsamVjiiRGscWRoaGmCPTkgmU3QrFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [lastLogon = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"lastLogon", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTimeZone.From([lastLogon]/ 864000000000 - 109205))
in
    #"Added Custom"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

View solution in original post

Hey Tommy,

When I use your formula into a new custom column, it appears me an error. How can I solve this?

 

photo query.PNG

Hello @xavipc_78 

 

add a ")" at the end

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

All right guy! Thank you so much

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors