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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Get value for approximate time

Hi there, 

 

I am looking to find a solution (preferably a calculated column) that will find a value of an item or an average for the closest time in Table 2 (+- 20 minutes). See example below for further clarification.

 

Could anyone point me to the right direction please?

 

Table 1 

Date     Time     Item     Table 2 Match     
01/01/2022     01:30     BB4     200     
01/01/2022     01:25     AA4     300     
01/01/2022     02:35     BB3     425 (average)     

 

Table 2 

Date     Time     Item     Value     
01/01/2022     01:25     BB4     200     
01/01/2022     01:25     AA4     300     
01/01/2022     02:40     BB3     450     
01/01/2022     02:15     BB3     400     
1 ACCEPTED SOLUTION
daniel79
Resolver II
Resolver II

Here's my take on this.

 

I first get the closest datetime for the same item and then average the values for the closest records with a tolerance of 20 mins.

daniel79_0-1653503066787.png

Measure

Avg Closest = 
    VAR vMAXTOL = 20
    VAR vDatetime = min(TABLE1[Datetime])
    VAR vClosest = CALCULATE(MINX(TABLE2,abs(TABLE2[Datetime2]-vDatetime)*24*60))
    VAR vAvg = AVERAGEX(filter(TABLE2,(abs(TABLE2[Datetime2]-vDatetime)*24*60)<=vClosest+0.00001 && vClosest<=vMAXTOL),TABLE2[Value])
return vAvg

 

Link to data and pbix file.

View solution in original post

2 REPLIES 2
daniel79
Resolver II
Resolver II

Here's my take on this.

 

I first get the closest datetime for the same item and then average the values for the closest records with a tolerance of 20 mins.

daniel79_0-1653503066787.png

Measure

Avg Closest = 
    VAR vMAXTOL = 20
    VAR vDatetime = min(TABLE1[Datetime])
    VAR vClosest = CALCULATE(MINX(TABLE2,abs(TABLE2[Datetime2]-vDatetime)*24*60))
    VAR vAvg = AVERAGEX(filter(TABLE2,(abs(TABLE2[Datetime2]-vDatetime)*24*60)<=vClosest+0.00001 && vClosest<=vMAXTOL),TABLE2[Value])
return vAvg

 

Link to data and pbix file.

Anonymous
Not applicable

This is brilliant Daniel - work's like magin as a measure. Do you think it would work the same as a calculated column? I would like to visualise the data and it does not seem to be working that easily. Thanks

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.