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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.