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
JimJim
Responsive Resident
Responsive Resident

Issue with DATESINPERIOD

Hi Guys,

Firstly, I am sorry for the lack of test data or even a pbix file, I tried replicating the issue in a test report so that I could demonstrate it to you, but I can't replicate the issue.

 

The problem:

Across many of our reports, we have a DAX function that is used throughout, it allows a user to select a month from a slicer and then a chart displays a rolling 13 months from the selected date. The DAX to do this is:

 

Quote Count Dynamic 13M = 
// get the selected date
VAR __selectedDate =
    MAX ( 'Time'[Date] )
// create a date table        
VAR __dates = 
        DATESINPERIOD('Time (previous months)'[CalendarDate],
        __selectedDate,
        -13,
        MONTH)
VAR __result = 
        CALCULATE([Quote Count],
            REMOVEFILTERS('time'),
            KEEPFILTERS(__dates),
            USERELATIONSHIP('Time (previous months)'[date], 'time'[date]))
RETURN
__result

 

Suddenly, when a user selects Dec-2023 the chart is blank, but strangely this isn't happening in all of our reports. There is no consistency, the DAX is identical in all report as is the relationship between date tables. 

 

I have identified that it is the __dates variable that returns no data when a user selects Dec-2023, for Nov-2023 __dates has 13 rows, but for Dec-2023 __dates is null. 

 

Does anyone have any suggestions?

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

replace this piece of code with the following

VAR __dates = 
        DATESINPERIOD('Time (previous months)'[CalendarDate],
        __selectedDate,
        -13,
        MONTH)

to

VAR __dates = 
        DATESBETWEEN('Time (previous months)'[CalendarDate]
        ,EDATE(__selectedDate,-13),__selectedDate)

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

replace this piece of code with the following

VAR __dates = 
        DATESINPERIOD('Time (previous months)'[CalendarDate],
        __selectedDate,
        -13,
        MONTH)

to

VAR __dates = 
        DATESBETWEEN('Time (previous months)'[CalendarDate]
        ,EDATE(__selectedDate,-13),__selectedDate)
JimJim
Responsive Resident
Responsive Resident

@Ahmedx , thank you. this works. But how? Is it a bug or am I being stupid?

Ahmedx
Super User
Super User

replace this piece of code with the following

VAR __dates = 
        DATESINPERIOD('Time (previous months)'[CalendarDate],
        __selectedDate,
        -13,
        MONTH)

to

VAR __dates = 
        DATESBETWEEN('Time (previous months)'[CalendarDate]
        ,EDATE(__selectedDate,-13),__selectedDate)

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