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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Allisond
Advocate II
Advocate II

Date Closest to a date AND within a window of time

I have a table of weights and dates and need to find a weight within a window of time (- 25 to -35 days)   AND then find the Wt that is closest to the actual 30 day date.   I can easily find the max weight within that window of time, but am struggling with how I would remove the Max and filter for the value closest to the actual 30 day mark.

 

ID                               Date                       WT

123                            12/01/20                 150

123                             11/29/20                 152

123                            12/5/20                     151.5

123                             1/1/21                     151

 

Return for the 1/1//21 Date would be 150   (12/1/20 wt).      Falls in the 30 day =/-5 days and is closest to actual 30 days.  

 

Any help would be so appreciated. 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Allisond ,

 

Create a date table and use it as silicer. Check the measures.

Measure = IF(SELECTEDVALUE('Table 2'[Date])<=SELECTEDVALUE('Table'[Date]),BLANK(),ABS(ABS(DATEDIFF(SELECTEDVALUE('Table 2'[Date]),SELECTEDVALUE('Table'[Date]),DAY))-30))

Measure 2 = 
var min_ = MINX(FILTER('Table',[Measure]<>BLANK()),[Measure])
return
IF(ISBLANK(min_)||min_>24,BLANK(),CALCULATE(SUM('Table'[WT]),FILTER('Table',[Measure]=min_)))

1.PNG

2.PNG

3.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @Allisond ,

 

Create a date table and use it as silicer. Check the measures.

Measure = IF(SELECTEDVALUE('Table 2'[Date])<=SELECTEDVALUE('Table'[Date]),BLANK(),ABS(ABS(DATEDIFF(SELECTEDVALUE('Table 2'[Date]),SELECTEDVALUE('Table'[Date]),DAY))-30))

Measure 2 = 
var min_ = MINX(FILTER('Table',[Measure]<>BLANK()),[Measure])
return
IF(ISBLANK(min_)||min_>24,BLANK(),CALCULATE(SUM('Table'[WT]),FILTER('Table',[Measure]=min_)))

1.PNG

2.PNG

3.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
lbendlin
Super User
Super User

Nah, this won't work. You need to describe how to break ties when (for example) one weight was done on 12/1/20 and another one on 12/3/20.  Why not intrapolate between the two weights ?

 

Also what should happen when there was no weight taken in the -35..-25 timeframe?

Blank if no weight in the window.  

What do you mean by intrapoloate between 2 weights? -- sorry somewhat of a newbee here.

Say you have 150 on 12/1 and 153 on 12/4. Draw a line between them and you get 151 for 12/2.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.