DAX度量值报错求助:PREVIOUSDAY中使用SELECTEDVALUE不被允许
Hey there, let's break down why that error is happening and get your measure working properly.
The Root Cause
The PREVIOUSDAY function is designed to take a date column from a table as its input, not a single scalar value. When you wrap B32_VS_PERIODS[DATE_BEGIN] in SELECTEDVALUE(), you're returning one specific date (a scalar) instead of the full column reference that PREVIOUSDAY needs. That's exactly why you're seeing the "SELECTEDVALUE used in a table filter expression" error—DAX can't substitute a single value where it expects a column for table-based functions.
Solutions
Depending on what you want your PreviousDay measure to do, here are two straightforward fixes:
1. Use DATEADD for a Single Previous Date
If your goal is to return the exact date that's one day before the selected date (a scalar value ideal for displaying in visuals), swap PREVIOUSDAY with DATEADD. This function works perfectly with scalar dates from SELECTEDVALUE:
PreviousDay = DATEADD(SELECTEDVALUE(B32_VS_PERIODS[DATE_BEGIN]), -1, DAY)
2. Use PREVIOUSDAY as a Filter (with CALCULATE)
If you need to fetch the previous day's date by filtering your date column and return it as a scalar, wrap PREVIOUSDAY in CALCULATE and use an aggregation like MAX to pull the single date value:
PreviousDay = CALCULATE(MAX(B32_VS_PERIODS[DATE_BEGIN]), PREVIOUSDAY(B32_VS_PERIODS[DATE_BEGIN]))
Here, PREVIOUSDAY(B32_VS_PERIODS[DATE_BEGIN]) returns a table containing just the previous day's date, and CALCULATE + MAX extracts that date as a usable scalar.
Quick Bonus Tip
If you're actually trying to filter your data to show results from the previous day (instead of just returning the date), this is the intended use case for PREVIOUSDAY—use it as a filter inside CALCULATE:
PreviousDaySales = CALCULATE(SUM(Sales[Amount]), PREVIOUSDAY(B32_VS_PERIODS[DATE_BEGIN]))
内容的提问来源于stack exchange,提问作者DevMJ

