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.
You can use the INTERPOLATE function in DAX to interpolate the blank values of Power based on the values of Eng Speed and Fuel Rate in Table 2. Here's an example DAX formula you can use:
Interpolated Power =
VAR EngSpeed = Table2[ENG_SPEED(RPM)]
VAR FuelRate = Table2[ENG_FUEL_RATE(kg/H)]
VAR Interpolated =
INTERPOLATE(
FILTER(Table1, Table1[Eng Speed(RPM)] = EngSpeed),
FuelRate,
Table1[Power(kW)]
)
RETURN
IF(ISBLANK(Table2[Power]), Interpolated, Table2[Power])
In this formula, we first define variables for Eng Speed and Fuel Rate from Table 2. Then we use the INTERPOLATE function to interpolate the Power values from Table 1 based on the Fuel Rate and the matching Eng Speed in Table 2. Finally, we use the IF and ISBLANK functions to return the interpolated Power value only for blank values in Table 2, and the original Power value for non-blank values.
- mohdasaad943 years ago
Helper I
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.
- rahul632soni3 years ago
Helper I
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