12.5 Use formulas to handle interval association

 

Here below is a data table:

imagepng

We want to calculate the price value in column B according to the quantity in column A, and the calculation should follow the rule: different quantity intervals correspond to different prices, as shown in the table below:

imagepng

Enter in cell B2:

=spl("=[15,13.75,13,12.5]([30,50,100,300,500].pseg@r(?1))",A2)

imagepng

Then drag B2 down to every relevant row:

imagepng

The idea of the calculation is to use the pseg function to calculate which interval the quantity value belongs to [30, 50, 100, 300, 500], and then take out the price of the corresponding interval from the price sequence [15, 13.75, 13, 12.5] and return.


https://c.scudata.com/article/1651916536524
https://c.scudata.com/article/1657467741165
https://c.scudata.com/article/1657506767759