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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
muktapurc
New Member

Please explain how to make Dynamic date filter for last month's data

 
1 ACCEPTED SOLUTION
v-heq-msft
Community Support
Community Support

Hi @muktapurc ,
You can create a measure

Dynamic Date Filter = 
VAR TodayDate = TODAY()
VAR FirstDayOfThisMonth = DATE(YEAR(TodayDate), MONTH(TodayDate), 1)
VAR LastDayOfLastMonth = FirstDayOfThisMonth - 1
VAR FirstDayOfLastMonth = DATE(YEAR(LastDayOfLastMonth), MONTH(LastDayOfLastMonth), 1)
RETURN
IF(
    SELECTEDVALUE('Table'[Date]) >= FirstDayOfLastMonth && SELECTEDVALUE('Table'[Date]) <= LastDayOfLastMonth,
    1,
    0
)

Apply the measure to the filter on this visual and set it is 1

vheqmsft_0-1733279668846.png

 

The above is a filter based on today's date, you can replace today() with your desired date

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

View solution in original post

4 REPLIES 4
v-heq-msft
Community Support
Community Support

Hi @muktapurc ,
You can create a measure

Dynamic Date Filter = 
VAR TodayDate = TODAY()
VAR FirstDayOfThisMonth = DATE(YEAR(TodayDate), MONTH(TodayDate), 1)
VAR LastDayOfLastMonth = FirstDayOfThisMonth - 1
VAR FirstDayOfLastMonth = DATE(YEAR(LastDayOfLastMonth), MONTH(LastDayOfLastMonth), 1)
RETURN
IF(
    SELECTEDVALUE('Table'[Date]) >= FirstDayOfLastMonth && SELECTEDVALUE('Table'[Date]) <= LastDayOfLastMonth,
    1,
    0
)

Apply the measure to the filter on this visual and set it is 1

vheqmsft_0-1733279668846.png

 

The above is a filter based on today's date, you can replace today() with your desired date

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

VAR FirstDayOfLastMonth =Date(Year(LastDayOfLastMonth),1)

 

Here you are adding one day to LastDayOfLastMonth?

Hi @muktapurc ,
You need to associate it with the previous variable

VAR FirstDayOfThisMonth = DATE(YEAR(TodayDate), MONTH(TodayDate), 1)

This line of code calculates the first day of the month and stores it in the variable FirstDayOfThisMonth.

VAR LastDayOfLastMonth = FirstDayOfThisMonth - 1

This line of code gets the last day of the previous month by subtracting one day from the first day of the month and storing it in the variable LastDayOfLastMonth.

VAR FirstDayOfLastMonth = DATE(YEAR(LastDayOfLastMonth), MONTH(LastDayOfLastMonth), 1)

This line of code calculates the first day of the previous month and stores it in the variable FirstDayOfLastMonth.
All of the above variables are obtained through you VAR TodayDate = TODAY() to do the calculations, in fact it's enough to just get this date.

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

PijushRoy
Super User
Super User

Hi @muktapurc 
Please share more details and screenshots to get an answer quickly




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.