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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
acamar22
Helper I
Helper I

Using a measure as a date column input in DATESINPERIOD

Hi all

 

I am trying to create some dynamic DAX code:

 

 

VAR DateRange = CALENDAR( MIN('FailureData[Date]),  MAX('FailureData[Date]) )

 

RETURN

CALCULATETABLE( other code ,  DATESINBETWEEN( DateRange, StartDate, -1, MONTH)   )

 

I am getting this error: DatesINPeriod functions are only accepting date column reference as a first argument.

 

I tried to use SELECTCOLUMN() for DateRange, but I get the same result.

 

I believe I just need to convert this single-column table into a column, but I'm not sure how. Any ideas?

 

Thanks

 

 

1 ACCEPTED SOLUTION

Hi, thanks for the suggestion, but I am still getting the same error, I've solved this by using FILTER() instead

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @acamar22 ,

Thank you @VN999  very much for the solution, and I've tried other ways to help you understand the problem:

When you make a mistake with SELECTCOLUMN(), my advice is to use VALUES for this

VAR DateRange = CALENDAR(MIN('FailureData'[Date]), MAX('FailureData'[Date]))
RETURN
CALCULATETABLE(
   'OtherTable',  // Replace with your actual table name or expression
   DATESINBETWEEN(
       VALUES(DateRange[Date]),  // This is a date column reference
       StartDate,  // 
       EDATE(StartDate, -1)  // 
   )
)

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

 

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

 

Hi, thanks for the suggestion, but I am still getting the same error, I've solved this by using FILTER() instead

VN999
Resolver I
Resolver I

Try with this below DAX code might help you:

 

VAR DateRange =
CALENDAR(
MIN('FailureData'[Date]),
MAX('FailureData'[Date])
)

RETURN
CALCULATETABLE(
'OtherTable', -- Replace 'OtherTable' with your actual table name or expression
DATESINPERIOD(
DateRange,
MAX('FailureData'[Date]), -- End date of the period
-1, -- Number of intervals to go back (-1 means previous month)
MONTH -- Interval type (MONTH, QUARTER, YEAR)
)
)

Hi @VN999 

Thanks for the response, however, this is what I already had.

 

The main problem is that the VAR DateRange is not being accepted as the first input into DATESINPERIOD().

 

I am trying to figure out why and how to fix it.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.