Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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 |
---|---|
76 | |
75 | |
54 | |
37 | |
31 |
User | Count |
---|---|
99 | |
56 | |
50 | |
42 | |
40 |