Forum Discussion
How to Interpolate Blank Values after lookup with multiple Condition in power BI
- 3 years ago
Try this another one:
se the DAX (Data Analysis Expressions) language to create a calculated column for interpolating the blank values. Since the data you have is not uniformly distributed, you can use a combination of LOOKUPVALUE and X functions to get the desired result.
- Create a relationship between the two tables in Power BI using the "Eng Speed" column.
- In Table 2, create a new calculated column, named "Interpolated Power", using the following DAX formula:
Interpolated Power =
VAR CurrentEngSpeed = Table2[ENG_SPEED(RPM)]
VAR CurrentFuelRate = Table2[ENG_FUEL_RATE(kg/H)]
VAR LowerBoundPower =
CALCULATE (
MAX ( Table1[Power(kW)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] <= CurrentFuelRate
)
)
VAR UpperBoundPower =
CALCULATE (
MIN ( Table1[Power(kW)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] >= CurrentFuelRate
)
)
VAR LowerBoundFuelRate =
CALCULATE (
MAX ( Table1[fuel(kg/h)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] <= CurrentFuelRate
)
)
VAR UpperBoundFuelRate =
CALCULATE (
MIN ( Table1[fuel(kg/h)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] >= CurrentFuelRate
)
)
VAR InterpolatedValue =
IF (
NOT ISBLANK ( LowerBoundPower )
&& NOT ISBLANK ( UpperBoundPower ),
DIVIDE (
CurrentFuelRate - LowerBoundFuelRate,
UpperBoundFuelRate - LowerBoundFuelRate
)
* ( UpperBoundPower - LowerBoundPower )
+ LowerBoundPower,
BLANK ()
)
RETURN
InterpolatedValue
This formula does the following:
- Defines the current "Eng Speed" and "Fuel Rate" values.
- Finds the nearest lower and upper bounds for "Power" and "Fuel Rate" in Table 1.
- Interpolates the "Power" value based on the difference between the current "Fuel Rate" and the lower and upper bounds.
- Returns the interpolated "Power" value or BLANK() if it cannot be calculated.
- The new calculated column "Interpolated Power" will contain the interpolated values based on the data in Table 1.
Keep in mind that this method assumes that your data in Table 1 is sorted in ascending order by "Fuel Rate". If it's not, you should sort it first.
Try this another one:
se the DAX (Data Analysis Expressions) language to create a calculated column for interpolating the blank values. Since the data you have is not uniformly distributed, you can use a combination of LOOKUPVALUE and X functions to get the desired result.
- Create a relationship between the two tables in Power BI using the "Eng Speed" column.
- In Table 2, create a new calculated column, named "Interpolated Power", using the following DAX formula:
Interpolated Power =
VAR CurrentEngSpeed = Table2[ENG_SPEED(RPM)]
VAR CurrentFuelRate = Table2[ENG_FUEL_RATE(kg/H)]
VAR LowerBoundPower =
CALCULATE (
MAX ( Table1[Power(kW)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] <= CurrentFuelRate
)
)
VAR UpperBoundPower =
CALCULATE (
MIN ( Table1[Power(kW)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] >= CurrentFuelRate
)
)
VAR LowerBoundFuelRate =
CALCULATE (
MAX ( Table1[fuel(kg/h)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] <= CurrentFuelRate
)
)
VAR UpperBoundFuelRate =
CALCULATE (
MIN ( Table1[fuel(kg/h)] ),
FILTER (
Table1,
Table1[Eng Speed(RPM)] = CurrentEngSpeed
&& Table1[fuel(kg/h)] >= CurrentFuelRate
)
)
VAR InterpolatedValue =
IF (
NOT ISBLANK ( LowerBoundPower )
&& NOT ISBLANK ( UpperBoundPower ),
DIVIDE (
CurrentFuelRate - LowerBoundFuelRate,
UpperBoundFuelRate - LowerBoundFuelRate
)
* ( UpperBoundPower - LowerBoundPower )
+ LowerBoundPower,
BLANK ()
)
RETURN
InterpolatedValue
This formula does the following:
- Defines the current "Eng Speed" and "Fuel Rate" values.
- Finds the nearest lower and upper bounds for "Power" and "Fuel Rate" in Table 1.
- Interpolates the "Power" value based on the difference between the current "Fuel Rate" and the lower and upper bounds.
- Returns the interpolated "Power" value or BLANK() if it cannot be calculated.
- The new calculated column "Interpolated Power" will contain the interpolated values based on the data in Table 1.
Keep in mind that this method assumes that your data in Table 1 is sorted in ascending order by "Fuel Rate". If it's not, you should sort it first.
Hey Its Working Fine but i am getting around 60% Blank Value in Iterpolated Power Column after uaing this Dax
Can you please Help ?
Regards
Rahul