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
Anonymous
Not applicable

How to write a filter to show data of the month after next month

Hi,

 

I am working to build a matrix to show data of the month after next month and can automatically update every month. For example, now it's June, so this will show all data of August. When it's July, this will auto update to show September's data.

 

I think I need to use a measure as a filter, but have no idea how to write it. May you help me?

 

Many thanks!

1 ACCEPTED SOLUTION

Ahh, what you need in addition is a column in your date table that calculates for "Current Month".

Month - Year = 
VAR CurrentYear =
    YEAR ( TODAY () )
VAR CurrentMonth =
    MONTH ( TODAY () )
RETURN
    IF (
        MONTH ( Dates[Date] ) = CurrentMonth
            && YEAR ( Dates[Date] ) = CurrentYear,
        "Current Month",
        FORMAT ( Dates[Date], "mmm-yyyy" )
    )

Every time your model refreshes this column will calculate and tag the current month as "Current Month".  Then, in your slicer just pick "Current Month" and it will shift the date range automatically as you go from month to month.

CurrentMonth.jpg

On July 1st the column [Month - Year] for all the rows in June will show "Jun-2019" and all the rows in July will show "Current Month".

View solution in original post

7 REPLIES 7
jdbuchanan71
Super User
Super User

Hello @Anonymous 

Give this a try

Month +2 = 
VAR SelectedDate = MAXX ( VALUES ( Table1[DATE] ) , [DATE] )
RETURN FORMAT ( DATE ( YEAR ( SelectedDate ), MONTH ( SelectedDate )+2, 1), "mmmm" )
Anonymous
Not applicable

Thanks for kind help!

 

But I still don't see how this can update data every month. I mean, should we include something like month(today()) ? And what does '1' mean in your FORMAT function?

 

Thanks so much!

Whatever month you have selected, this measure will return 2 months from that.  

The part of the formula with the 1 is just calcing the date with 2 months added and returning the month name.

So, if you picked June 20th 2019 in your data table

Selected Date will be 6/20/2019

 

  • DATE ( YEAR ( 6/20/2019 ), MOTH ( 6/20/2019) +2, 1)
  • DATE ( 2019, 6 + 2, 1 )
  • DATE ( 2019, 8, 1)
  • 8/1/2019
  • FORMAT ( 8/1/2019, "mmmm" )
  • = August

 

Anonymous
Not applicable

I totally understand the code and learn a lot from it, thanks so much!

 

But this still cannot auto update. I mean, when it's June, I want it show data of August automatically; when it becomes July, it will show September automativally. For your code, I need to change in filter from 'is August' to 'is September' to get the same result, but this is not automatically.

 

Thanks again!!  

Ahh, what you need in addition is a column in your date table that calculates for "Current Month".

Month - Year = 
VAR CurrentYear =
    YEAR ( TODAY () )
VAR CurrentMonth =
    MONTH ( TODAY () )
RETURN
    IF (
        MONTH ( Dates[Date] ) = CurrentMonth
            && YEAR ( Dates[Date] ) = CurrentYear,
        "Current Month",
        FORMAT ( Dates[Date], "mmm-yyyy" )
    )

Every time your model refreshes this column will calculate and tag the current month as "Current Month".  Then, in your slicer just pick "Current Month" and it will shift the date range automatically as you go from month to month.

CurrentMonth.jpg

On July 1st the column [Month - Year] for all the rows in June will show "Jun-2019" and all the rows in July will show "Current Month".

Anonymous
Not applicable

I have a similar question. I got it to always select the current month, however, how can I add to this code to also automatically select previous month and same month last year? I couldn't find anything when researching. I just want to expand on the code below if possible.

 

Report Month = IF(MONTH(now()) = Month(DateTable[date]) && YEAR(now()) = YEAR(DateTable[date]), "Current Month", DateTable[Month_year])
 

Jporter_0-1606936152914.png

 

Anonymous
Not applicable

I've added something to your code to deal with Month11&1 and 12&2.

 

Man, you are great!

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.