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
2019
Helper II
Helper II

Filter As Per Last N Months, Current Month and Next N Months

I have a table where I want to filter information in power query as per a date column (Start Date) in the table when are meeting the following criteria:

 

  1. Last 2 Months &
  2. Current Month &
  3. Next 6 Months

I cannot use (group by) and load the maximum values (latest) because I do have future year values.

 

Please find attached excel sheet data source file (click here), you can check my draft PBI file (click here)

 

Capture.PNG

1 ACCEPTED SOLUTION

I was just thinking this might be better:

 

let
    _TwoMonthsAgo =  Date.StartOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), -2)),
    _SixMonthsAhead = Date.EndOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), 6)),
    _FilterDate = Table.SelectRows(YOURTABLE, each [Start Date] >= _TwoMonthsAgo and [Start Date] <= _SixMonthsAhead)
in
    _FilterDate

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

You can use the isinprevious and isinthenext date/tiem filter options when select the dropdown from the column you want to filter

 

example below

 

Table.SelectRows(FilterFiles, each Date.IsInPreviousNMonths([Date created], 2))

Anonymous
Not applicable

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fV1bjx03jv4rizOv6QNdS1WPne62247j+JKN7QzmwTMIBov1zgbGehf2r98qkRI/Siy/Gc0jlS68fqTov/718uaa8nL54RKWm+dfPt34df/3vSvL5W8/7MQv17iEg3rz88evN34jYm7EsMT9L/6gfu7UjahXv8Rvx9B88/aPP4n6+MI71wb7uP59/1t0+4f/RfSn0W2NnPZf7nPjh1cee83eHzOXm/s//jGvytUl+3Rz++fnm5D3f7/6+Pk/eWj0Cy3ZIO4fXY6J/XLz5I+/3wSnvnosqZ4UbTd48zCWm5f//b/zmng3rlLrxPoslkr2dVVtcOElu2WlRR275UU14r7bdPy81BW3Q1z7vOlYZaRzWocT9nXkfk4m1W31oNTY/dgbNdc1rWrBud18Oc41y0ngvLEcI8N288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ffp7/cuqhjbi7e+Z02wztZbE39/+fJ2kDnLr3F86BMVIgL5wJfOcxqhURhcQegB4M3H3HzNPQV2ICxKh7DXAA6fRS/bcYAplXUrYuaHGnGZu3fs20zUgjBeVj+rqxfICMYfyyzetBlT+aW2dw/8cPaH3gAMErxi7AOPz87VTMr1zwftTZOxDqeikCcj3T0p0FD3Q+FM6QUhD1PG3/wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Start Date" = _t, Asset = _t]),
    #"Modificato tipo" = Table.TransformColumnTypes(Origine,{{"Item", type text}, {"Start Date", type date}, {"Asset", type text}}, "en-US"),
    #"Ordinate righe" = Table.Sort(#"Modificato tipo",{{"Start Date", Order.Ascending}}),
    #"Raggruppate righe" = Table.Group(#"Ordinate righe", {"Start Date"}, {{"all", each _},{"quanti", each Table.RowCount(_)}},GroupKind.Local,(x,y)=>Date.Month(x[Start Date])-Date.Month(y[Start Date])),
    #"Aggiunta colonna personalizzata" = Table.AddColumn(#"Raggruppate righe", "lastNmonths", each LCN([Start Date],2,6))
in
    #"Aggiunta colonna personalizzata"

 

 

 

where LCN is:

 

let
    lastNCurrNextM=(d,n,m) =>
    let 
     curr=Date.From(Date.StartOfMonth( DateTime.LocalNow())),
     lastN=Date.AddMonths(curr,-n),
     nextM=Date.AddMonths(curr,+m+1),
     md=Date.StartOfMonth(d),
     res=if md < lastN then "too past" else
                if md <curr then "lastN" else 
                if md=curr then "current" else 
                if md <nextM then "nextm" else "too future"
in
    res
    in lastNCurrNextM
justinh
Advocate IV
Advocate IV

Try this (or something like it, I'm writing it this off the top of my head, so the syntax might be wrong.)

 

let

    _CurrentMonthStart = Date.StartOfMonth(DateTime.FixedLocalNow()),
    _CurrentMonthEnd = Date.EndOfMonth(DateTime.FixedLocalNow()),
    _TwoMonthsAgo = Date.AddMonths(_CurrentMonthStart, -2),
    _SixMonthsAhead = Date.AddMonths(_CurrentMonthEnd, 6),
    _FilterDate = Table.SelectRows(_YOURTABLE, each [Start Date] >= _TwoMonthsAgo and [Start Date] <= _SixMonthsAhead)
in
    _FilterDate
 

 

 

I was just thinking this might be better:

 

let
    _TwoMonthsAgo =  Date.StartOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), -2)),
    _SixMonthsAhead = Date.EndOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), 6)),
    _FilterDate = Table.SelectRows(YOURTABLE, each [Start Date] >= _TwoMonthsAgo and [Start Date] <= _SixMonthsAhead)
in
    _FilterDate

@justinh 

I used your method and it succeeded 100%, Thank you so much and also to the others who provided their solutions.

I have made minor changes to the code and I used power query formatter to make it look like this:

 

#"FilterDate" = 
    let
      _Last2Months = Date.StartOfMonth(Date.AddMonths(DateTime.Date(DateTime.FixedLocalNow()), - 2)),
      _Next6Months = Date.EndOfMonth(Date.AddMonths(DateTime.Date(DateTime.FixedLocalNow()), 6))
    in
      Table.SelectRows(
        #"Replaced Value1",
        each [Start Date] >= _Last2Months and [Start Date] <= _Next6Months
      )

 

 

Awesome! I'm glad it worked for you!

CNENFRNL
Community Champion
Community Champion

Hi, @2019 , you might want to try adding a customed column in PQ,

#"Added Custom" =
    let
        Today = DateTime.Date(DateTime.LocalNow()),
        Days_Till_Next_6_Months = Duration.Days(Date.AddMonths(Today,6)-Today)
    in
        Table.AddColumn(
            #"Replaced Value1",
            "Criteria", each
                if Date.IsInCurrentMonth([Start Date]) then "Current Month" else if Date.IsInPreviousMonth([Start Date]) then "Last 2 Months" else let Diff = Duration.Days([Start Date]-Today) in if Diff>0 and Diff<=Days_Till_Next_6_Months then "Next 6 Months" else "Other"
)

Screenshot 2021-02-06 072439.png

 

Here is the pbix file for your reference.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank you @CNENFRNL  for providing assistant to accomplish this, I have tried your approach but I have found out the below:

 

1. Last 2 months:

For the last 2 months you are using this code Date.IsInPreviousMonth([Start Date]) will return back the last 1 month info instead of 2 month info,

For example, when I filter the Criteria column to last 2 months I only see Jan-2021 info and there are no info for Dec-2020

Is there away where I can filter as per the last N months (N is where I specify number of months).

 

2. Next 6 Months:

I have tried your approach but I have found out if I filter the Criteria column to Next 6 Months,  

For Aug-2021 it shows me only 4 rows instead of total 16 rows

Is there a way to accomplish that?

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors