finding the nearest

fransbus

New Member
Joined
Mar 13, 2013
Messages
3
Although I have worked with "Gemini" ages ago I consider myself new to Powerpivot. I am looking for assistance on this question:
I have two unrelated tables like this:
Code:
Table1:
Index    Year    Score
    1    2009    10
    2    2009    12
    3    2009    14
    4    2009    16
    5    2009    18
    6    2010    14
    7    2010    16
    8    2010    18
    9    2010    20
   10    2010    22

Table2:
Year    Score    Min    Index
2009    8        2        1
2009    17       1       16 or 18
2010    8        6        6
2010    18       0        8
2010    26       4       10
Min and Index in Table2 are Calc columns. What I need: for each row (Year/Score) in Table 2 I want to get Index from Table 1 where Table2.Score is closest to Table1.Score, and Table2.Year = Table1.Year.

This is easy in Excel using an array formula with Index, Match and If, but I can't find the formula for Index in Powerpivot. Any ideas? Thx.

Note: the formula for Min could be something like
=MINX(VALUES(Table1[Score]); ABS(Table1[Score] - Table4[Score]))
But it's not Min I need. I need Index.

- Frans
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Solved it. Used 4 calc columns.
Table1 above is now tblScores, Table2 is now tblNewScores.
Code:
Calc formula SmallestDistanceToScore:
=MINX( FILTER(tblScores; tblScores[Year] = tblNewScores[Year]); ABS(tblScores[Score] - tblNewScores[Score]))

Calc formula Index1:
=MINX( FILTER(tblScores; tblScores[Year] = tblNewScores[Year] && ABS(tblScores[Score] - tblNewScores[Score]) = tblNewScores[SmallestDistanceToScore]); tblScores[Index])

Calc formula CountMatches:
=COUNTX( FILTER(tblScores; tblScores[Year] = tblNewScores[Year] && ABS(tblScores[Score] - tblNewScores[Score]) = tblNewScores[SmallestDistanceToScore]); tblScores[Index])

Calc formula Index2:
=IF([CountMatches]=1; BLANK(); MAXX( FILTER(tblScores; tblScores[Year] = tblNewScores[Year] && ABS(tblScores[Score] - tblNewScores[Score]) = tblNewScores[SmallestDistanceToScore]); tblScores[Index]))

Regards,
- Frans
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top