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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Niklerus
New Member

Help with dynamic date filter for month and day of month

Hi,

Need help to set up a dynamic date filter which is in relation to date when query is run.

I only want rows where date is before the 15th in the previous month.

I got started with below but I can't get the syntax right, I can get it to work for rows before current month but the 15th day part I can't get right:

Table.SelectRows(#"Removed Columns", each [enrolled_date] < (Date.AddMonths(DateTime.FixedLocalNow(),-1),Date.AddDays(DateTime.FixedLocalNow(),-15))

 

Any help appreciated!

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Niklerus ,

 

Try this:

 

 

Table.SelectRows(
    #"Removed Columns",
    each let Date.Today = Date.From(DateTime.LocalNow()) in
    [enrolled_date] <
    #date(
        Date.Year(Date.AddMonths(Date.Today, -1)),
        Date.Month(Date.AddMonths(Date.Today, -1)),
        15
    )
)

 

 

 

or more inline:

 

Table.SelectRows(
    #"Removed Columns",
    each [enrolled_date] <
    #date(
        Date.Year(Date.AddMonths(Date.From(DateTime.LocalNow()), -1)),
        Date.Month(Date.AddMonths(Date.From(DateTime.LocalNow()), -1)),
        15
    )
)

 

 

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

7 REPLIES 7
Einomi
Helper V
Helper V

Hi @Niklerus 

 

You can try this

 

let
    Source = Excel.CurrentWorkbook(){[Name="Tableau1"]}[Content],
    #"Lignes filtrées" = Table.SelectRows(Source, each Date.IsInPreviousMonth([enrolled_date]) and Date.Day([enrolled_date]) < 15)
in
    #"Lignes filtrées"
Fowmy
Super User
Super User

@Niklerus 

= Table.SelectRows(#"Removed Columns", each [enrolled_date] < Date.AddDays(Date.AddMonths(  Date.StartOfMonth( Date.From(DateTime.FixedLocalNow()) ) , -1), 14))
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

BA_Pete
Super User
Super User

Hi @Niklerus ,

 

Try this:

 

 

Table.SelectRows(
    #"Removed Columns",
    each let Date.Today = Date.From(DateTime.LocalNow()) in
    [enrolled_date] <
    #date(
        Date.Year(Date.AddMonths(Date.Today, -1)),
        Date.Month(Date.AddMonths(Date.Today, -1)),
        15
    )
)

 

 

 

or more inline:

 

Table.SelectRows(
    #"Removed Columns",
    each [enrolled_date] <
    #date(
        Date.Year(Date.AddMonths(Date.From(DateTime.LocalNow()), -1)),
        Date.Month(Date.AddMonths(Date.From(DateTime.LocalNow()), -1)),
        15
    )
)

 

 

Pete



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

Proud to be a Datanaut!




@BA_Pete for the sake of others coming here looking for a solution, the "more inline" version of code doesn't  work, I get: Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

I pasted both versions as is and the first one works great, the other one does not.
(I wanted to try the second one as it seems a little bit easier to learn/remember the syntax)

Found the issue with the second code example, there was an each missing before [enrolled_date]

 

You're absolutely right, my mistake.

I've updated the inline code so should now work.

Thanks for the heads-up 👍

 

Pete



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

Proud to be a Datanaut!




Beatiful!

Big thank you!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors