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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
shamilka
Frequent Visitor

Converting a number to the current date

I want to do following two things in power query

 

1. My database contains dates as a number as per the table below. I want to convert it to a date recognized by Power BI.

2. Need to develop a power query code to get the data recorded for the past 3 days from today. 

 

Note: the Date number is eqal to the number of days from a specific constant date (Ex: Date number = number of days from 13.12.2000 = 1550)

 

Part noBatch noPurchase OrderDate number
155100008A10031550
153100008A10041549
154100008A10051543
155100008A10061540

 

Thank you

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @shamilka, last step is blank table because sample data are year 2005.

 

dufoq3_0-1711608924424.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1VdJRMjQAAgsgwxHIMgYJmJoaKMXqgOSN0eVNwPImllB5E3R5U4i8MVQew3wziDzQ/FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part no" = _t, #"Batch no" = _t, #"Purchase Order" = _t, #"Date number" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Part no", Int64.Type}, {"Batch no", Int64.Type}, {"Purchase Order", type text}, {"Date number", Int64.Type}}),
    Ad_Date = Table.AddColumn(ChangedType, "Date", each Date.AddDays(#date(2000,12,13), [Date number]), type date),
    FilteredLastThreeDaysFromToday = Table.SelectRows(Ad_Date, each [Date] >= Date.AddDays(Date.From(DateTime.LocalNow()), -2))
in
    FilteredLastThreeDaysFromToday

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

1 REPLY 1
dufoq3
Super User
Super User

Hi @shamilka, last step is blank table because sample data are year 2005.

 

dufoq3_0-1711608924424.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1VdJRMjQAAgsgwxHIMgYJmJoaKMXqgOSN0eVNwPImllB5E3R5U4i8MVQew3wziDzQ/FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part no" = _t, #"Batch no" = _t, #"Purchase Order" = _t, #"Date number" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Part no", Int64.Type}, {"Batch no", Int64.Type}, {"Purchase Order", type text}, {"Date number", Int64.Type}}),
    Ad_Date = Table.AddColumn(ChangedType, "Date", each Date.AddDays(#date(2000,12,13), [Date number]), type date),
    FilteredLastThreeDaysFromToday = Table.SelectRows(Ad_Date, each [Date] >= Date.AddDays(Date.From(DateTime.LocalNow()), -2))
in
    FilteredLastThreeDaysFromToday

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors