Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I have this table:
And, based on a Calendar Date filter, I want to get the Value based on the closest date.
For example
- If I filter the 7/12/2022, I want to get the Value = 23 (The next closest date in the table is 17/12/2022)
- If I filter the 22/12/2022, I want to get the Value = 21 (The next closest date in the table is 25/12/2022)
- If I filter the 20/12/2022, I want to get the Value = 15
I need to perform this on DAX. Thanks
Solved! Go to Solution.
Hi @Anonymous
Try this measure. It assumes there is NO relationship between your date and fact tables. FactT is the table you show above.
Measure_ =
VAR selected_ = SELECTEDVALUE ( CalendarT[Date] )
VAR lower_ =
CALCULATE ( MAX ( FactT[Date] ), FactT[Date] <= selected_ )
VAR higher_ =
CALCULATE ( MIN ( FactT[Date] ), FactT[Date] > selected_ )
RETURN
IF (
ABS ( higher_ - selected_ ) < ABS ( lower_ - selected_ ),
CALCULATE ( DISTINCT ( FactT[Value] ), FactT[Date] = higher_ ),
CALCULATE ( DISTINCT ( FactT[Value] ), FactT[Date] = lower_ )
)
If this does not work, do share a pbix with sample data
|
Please accept the solution when done and consider giving a thumbs up if posts are helpful. Contact me privately for support with any larger-scale BI needs, tutoring, etc. |
Hi @Anonymous
Try this measure. It assumes there is NO relationship between your date and fact tables. FactT is the table you show above.
Measure_ =
VAR selected_ = SELECTEDVALUE ( CalendarT[Date] )
VAR lower_ =
CALCULATE ( MAX ( FactT[Date] ), FactT[Date] <= selected_ )
VAR higher_ =
CALCULATE ( MIN ( FactT[Date] ), FactT[Date] > selected_ )
RETURN
IF (
ABS ( higher_ - selected_ ) < ABS ( lower_ - selected_ ),
CALCULATE ( DISTINCT ( FactT[Value] ), FactT[Date] = higher_ ),
CALCULATE ( DISTINCT ( FactT[Value] ), FactT[Date] = lower_ )
)
If this does not work, do share a pbix with sample data
|
Please accept the solution when done and consider giving a thumbs up if posts are helpful. Contact me privately for support with any larger-scale BI needs, tutoring, etc. |
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
79 | |
78 | |
59 | |
36 | |
33 |
User | Count |
---|---|
93 | |
59 | |
56 | |
49 | |
41 |