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
muktapurc
Regular Visitor

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

 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

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?

Anonymous
Not applicable

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
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!

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 Solution Authors
Top Kudoed Authors