Forum Discussion

BI2018No's avatar
BI2018No
Frequent Visitor
7 years ago
Solved

Linear Interpolation with a lookup table

Hello! I'm new to Power BI, but I try my best to convert some of my old Excel sheets to Power BI.   I want to perform linear interpolation based on values in a seperate table. This table describes ...
  • Greg_Deckler's avatar
    Greg_Deckler
    7 years ago

    So, if I understand what you are saying, you want sensor ID=0 to only interpolate over your known entities table with a corresponding ID=0 and ID=1 should only interpolate over ID=1 known entities, correct? Let me know if that is correct, shouldn't be difficult at all to modify the formula. So, using my original formula, you could probably do something like below (which assumes that you have unrelated tables that both have an ID column 

     

    Pressure (MPa)  = 
    VAR x3 = MAX(Interpolation[Temp (C)]) //This is the known value for which you wish to interpolate another value
    
    VAR __id = MAX(Interpolation[ID] // current ID
    
    VAR match = CALCULATE(MAX(H2OTempSat[Pressure (MPa)]),FILTER(H2OTempSat,[Temp (C)]=x3 && [ID]=__id)) //checks if it is a known value
    
    VAR x1 = CALCULATE(MAX(H2OTempSat[Temp (C)]),FILTER(H2OTempSat,[Temp (C)]<=x3 && [ID]=__id)) //low X value
    
    VAR x2 = CALCULATE(MIN(H2OTempSat[Temp (C)]),FILTER(H2OTempSat,[Temp (C)]>=x3 && [ID]=__id)) //high X value
    
    VAR y1 = CALCULATE(MAX(H2OTempSat[Pressure (MPa)]),FILTER(H2OTempSat,[Temp (C)]<=x3 && [ID]=__id)) //low Y value
    
    VAR y2 = CALCULATE(MIN(H2OTempSat[Pressure (MPa)]),FILTER(H2OTempSat,[Temp (C)]>=x3 && [ID]=__id)) //low X value
    
    RETURN IF(NOT(ISBLANK(match)),match,y1 + (x3 - x1) * (y2 - y1)/(x2 - x1)) //if a match, return match otherwise interpolate