Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to Solution.
Hi, thanks for the suggestion, but I am still getting the same error, I've solved this by using FILTER() instead
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
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.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
11 | |
9 | |
6 |