Hey guys i could really use some help coding this IF statement! I managed to fit in 2 of the conditions, not sure how the 3rd (calculation) would fit in. This is the calc in pseudocode;
IF Producer_Type = 'Oil', Unallocated OIL&GAS = UnallocatedLossesOIL
IF Producer_Type = 'Gas', Unallocated OIL&GAS = UnallocatedLossesGAS
ELSE Unallocated OIL GAS = UnallocatedLossesOIL(MPPOil ÷ (MPPOil + MPPGas)) +
UnallocatedLossesGAS(MPPGas ÷ (MPPOil + MPPGas))
This is my code:
SELECT qb1.CompanyName, qb1.AssetName, qb1.Year,
IIf(qb1.Producer_Type='Oil',qb1.DatapointValue, qb2.DatapointValue) AS UnallocatedOilGas
FROM PEBaseQuery AS qb1 INNER JOIN PEBaseQuery AS qb2 ON qb1.Assetname=qb2.AssetName
WHERE qb1.DatapointID=2026 And qb2.DatapointID=2027;
Where DatapointID of 2026 is UnallocatedLossesOIL and 2027 is UnallocatedLossesGAS. The calculation needs to reference MPPOil and MPPGas values (relating to particular companies/assets/yearswhich are results from two separate queries… Any help would be much appreciated! Sorry if some of this doesnt make sense..
How about nesting the if condition? I mean, if thats possible, this should work:
Regarding the values of
MPPGasandMPPOil, I’m not sure where to find them, so left them as they are.I hope this works.