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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AOT
Frequent Visitor

Help with M power query

I need to filter a column have dates between DateTime.FixedLocalNow()) and Date.AddDays((DateTime.FixedLocalNow()), 91)).

 

But I cannot seem to get the right M query script.

 

Please help.

 

This is currently what I have done. But it doesn't seem to filter the column properly. The column is [end_date]

 

#"Filtered Rows2" = Table.SelectRows(#"Changed Type", each [end_date] > DateTime.FixedLocalNow()),
#"Filtered Rows3" = Table.SelectRows(#"Changed Type", each [end_date] < Date.AddDays((DateTime.FixedLocalNow()), 91))

1 ACCEPTED SOLUTION

Hi @AOT 

 

Not sure if I've understood your requirement correctly, but I believe this should work as a replacement for your #"Filtered Rows2" step:

 

#"Filtered Rows2" = Table.SelectRows(#"Extracted Date1", each Date.From([end_date]) = Date.From(DateTime.FixedLocalNow()) or Date.IsInNextNDays(Date.From([end_date]), 91)),

 

I've used the Date.From() surrounds on the [end_date] column refs so you aren't required to use your "Extracted Date" step if you don't want to.

 

Remember to remove the comma at the end if this is the last step in your query

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

6 REPLIES 6
v-frfei-msft
Community Support
Community Support

Hi @AOT ,

 

If you want to make your code work, you should change your date to date.time. Or you can update your M code as below.

 

1.PNG2.PNG

 

= Table.SelectRows(#"Changed Type", each [Date] >= Date.From(DateTime.FixedLocalNow()) and [Date] <= Date.From(Date.AddDays((DateTime.FixedLocalNow()), 91)))

 

Full code for your reference as well.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc65DcAwDMXQXVQHsL7sHJ5F8P5ruEgQUOUDG2aamlq4pq0jLYhODOIkLuImHmIS8qLyoDLxpnDsfejE+LE2", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Date] >= Date.From(DateTime.FixedLocalNow()) and [Date] <= Date.From(Date.AddDays((DateTime.FixedLocalNow()), 91)))
in
    #"Filtered Rows"

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @v-frfei-msft ,

 

When I put in the step, there are no syntax errors but I keep on getting this error. Do you know what this means?

 

Annotation 2019-12-11 112258.png

 
 

Hi @AOT ,

 

Could you please share your sample data or pbix to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @v-frfei-msft ,

 

This is the code so far

 

Source = Impala.Database("impalahs2dr.unix.marksandspencer.com:25003"),
spotfire_reporting_views_Schema = Source{[Name="spotfire_reporting_views",Kind="Schema"]}[Data],
t_irp_phase_new_sc_Table = spotfire_reporting_views_Schema{[Name="t_irp_phase_new_sc",Kind="Table"]}[Data],
#"Added Conditional Column" = Table.AddColumn(t_irp_phase_new_sc_Table, "articlev", each if [variant_no] = null then [article_id] else [variant_no]),
#"Changed Type" = Table.TransformColumnTypes(#"Added Conditional Column",{{"start_date", type datetime}, {"end_date", type datetime}}),
#"Extracted Date" = Table.TransformColumns(#"Changed Type",{{"start_date", DateTime.Date, type date}}),
#"Filtered Rows1" = Table.SelectRows(#"Extracted Date", each [start_date] > Date.From(DateTime.FixedLocalNow())),
#"Extracted Date1" = Table.TransformColumns(#"Filtered Rows1", {{"end_date", DateTime.Date, type date}}),
#"Filtered Rows2" = Table.SelectRows(#"Extracted Date1", each [end_date] <= Date.From(Date.AddDays((DateTime.FixedLocalNow()), 84)) and [end_date] >= Date.From(DateTime.FixedLocalNow())),

Hi @AOT 

 

Not sure if I've understood your requirement correctly, but I believe this should work as a replacement for your #"Filtered Rows2" step:

 

#"Filtered Rows2" = Table.SelectRows(#"Extracted Date1", each Date.From([end_date]) = Date.From(DateTime.FixedLocalNow()) or Date.IsInNextNDays(Date.From([end_date]), 91)),

 

I've used the Date.From() surrounds on the [end_date] column refs so you aren't required to use your "Extracted Date" step if you don't want to.

 

Remember to remove the comma at the end if this is the last step in your query

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Mariusz
Community Champion
Community Champion

Hi @AOT 

 

If your column is a date data type then try adding Date.From( DateTime.FixedLocalNow() ) around this should work.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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