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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to write a dax query to get last 15 days data (15 days date range)?

How to write a dax query to get last 15 days data (15 days date range)?

Alice08_0-1704968855480.png

i tried using this but its giving error.

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this

if [Due Date] >= Date.AddDays( Date.From(DateTime.LocalNow()),-15) and [Due Date] <= Date.From(DateTime.LocalNow()) then "15" else [Due Date]

Screenshot_1.png

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

pls try this

if [Due Date] >= Date.AddDays( Date.From(DateTime.LocalNow()),-15) and [Due Date] <= Date.From(DateTime.LocalNow()) then "15" else [Due Date]

Screenshot_1.png

Joel_Cami
Frequent Visitor

In DAX you can use DATEADD for showing and interval, but in your case you would like to see last days from today?


I you want to do this, you can create a calendar table in DAX and agregate a calculate column for DAX. In this example shows last 15 days from today

Last15Days =
VAR DayOfToday =
    TODAY()
VAR DateTable = 'Calendar Example'[Date]
VAR DAY15 = DayOfToday - 15
RETURN
    IF(
        DateTable >= DAY15
            && DateTable <= DayOfToday,
        DateTable,
        BLANK()
    )

Joel_Cami_0-1704970408329.png

 

I hope this solution helps you
 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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