I'm having a hard time coming up with an elegant solution for this. I have a table that explains legal tolerances for nutrition based on certain analytes and their values
Table look like this, but has many more values in it
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Analyte[/TD]
[TD]Declared Content [/TD]
[TD]Tolerance Below[/TD]
[TD]Tolerance Above[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]<16[/TD]
[TD]2[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]16-24[/TD]
[TD]12.5%[/TD]
[TD]25%[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]>24[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]<2[/TD]
[TD]no limit[/TD]
[TD]0.4[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]2-5[/TD]
[TD]no limit[/TD]
[TD]20%[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]5-12.5[/TD]
[TD]no limit[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]>12.5[/TD]
[TD]no limit[/TD]
[TD]8%[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]<8[/TD]
[TD]2[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]8-32[/TD]
[TD]25%[/TD]
[TD]12.5%[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]>32[/TD]
[TD]8[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]
Just to give an example:
If the declared content of fat is 8, the tolerance below is 8-2=6, and above is 8+4=12
If the declared content of fat is 20, the tolerance below is 20-20*12.5%=17.5, and the tolerance above is 20+20*25%=25
So on the input side we will have a table that has the analytes and the declared values, and the output side will have the tolerances.
The input side can also have the analytes arranged in any order, not necessarily the same order.
The only solution I have is creating a table to arrange the analytes in a specific order and then having to to put in if statements based on specific analytes and ranges
eg. for fat putting in: =if(A2<16,A2-B2,if(A2>24,A2-3,A2-A2*0.125))
Is there an elegant solution where I won't have to change each formula should the tolerances change? That is, I can just update the table, and not have to update each formula when the table changes?
Table look like this, but has many more values in it
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Analyte[/TD]
[TD]Declared Content [/TD]
[TD]Tolerance Below[/TD]
[TD]Tolerance Above[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]<16[/TD]
[TD]2[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]16-24[/TD]
[TD]12.5%[/TD]
[TD]25%[/TD]
[/TR]
[TR]
[TD]Fat[/TD]
[TD]>24[/TD]
[TD]3[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]<2[/TD]
[TD]no limit[/TD]
[TD]0.4[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]2-5[/TD]
[TD]no limit[/TD]
[TD]20%[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]5-12.5[/TD]
[TD]no limit[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Moisture[/TD]
[TD]>12.5[/TD]
[TD]no limit[/TD]
[TD]8%[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]<8[/TD]
[TD]2[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]8-32[/TD]
[TD]25%[/TD]
[TD]12.5%[/TD]
[/TR]
[TR]
[TD]Ash[/TD]
[TD]>32[/TD]
[TD]8[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]
Just to give an example:
If the declared content of fat is 8, the tolerance below is 8-2=6, and above is 8+4=12
If the declared content of fat is 20, the tolerance below is 20-20*12.5%=17.5, and the tolerance above is 20+20*25%=25
So on the input side we will have a table that has the analytes and the declared values, and the output side will have the tolerances.
The input side can also have the analytes arranged in any order, not necessarily the same order.
The only solution I have is creating a table to arrange the analytes in a specific order and then having to to put in if statements based on specific analytes and ranges
eg. for fat putting in: =if(A2<16,A2-B2,if(A2>24,A2-3,A2-A2*0.125))
Is there an elegant solution where I won't have to change each formula should the tolerances change? That is, I can just update the table, and not have to update each formula when the table changes?