You test this best with a number like

In this example we work with the Price As Of, see my blog to understand this principle.

This link can't be embedded.

The additional complexity in this example is that you cannot buy any volume, it should always be at least 1000 kg and this is because this is the lowest value in the range. Meaning that if you want to buy 100, you buy 1000 and if you want to buy 1100 you have to purchase 2000.

Below the first steps:

@1 | Sand $176.74 per 1,000 kg

@1 | Sand $176.74 per 1,000 kg

### CODE part A

→ part 01: we ask for all values when they are lower or equal to the volumeInkg. This results in a list of items that fit this specific criteria.

`[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min()))`

→ part 02: since we asked for a list of items, but we only need one, we added Last() and not First() and this due to the smaller or equal to logic.

`[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min())).Last()`

→ part 03: so far we asked for nothing special and then the fall back value is what you see in the display column. It is time to ask for the price per kg and so we add this parameter, but not before we renamed the main part of the formula as 'Base'. Renaming is an easy way to shorten your functions.

`[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min())).Last().WithName(Base,`

` `

` Base.pricePerKg)`

→ part 04: to get the price we multiply with the volume using the function Product()

`[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min())).Last().WithName(Base,`

` `

`Product(Base.pricePerKg,_Volume))`

So far we did not take into account that the volume bought should be a multiplier of the lowest volume in the list, in our case 1000. We need in part B we bring the multiplier into account.

### CODE part B

The first part of solution for the rounding problem is the one below: → `Quotient( _Volume , [DB Sand].VolumeInKg.Min()).RoundUp()`

The second part is bringing the value back `Quotient( _Volume , [DB Sand].VolumeInKg.Min()).RoundUp() * [DB Sand].VolumeInKg.Min()`

Last we relate his volume to the price per unit. and we do so by integrating step 4 of part A with the previous step. `[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min())).Last().WithName(Base,`

` `

` Quotient( _Volume , [DB Sand].VolumeInKg.Min()).RoundUp() * [DB Sand].VolumeInKg.Min().WithName(NewVolume, `

` `

`Product(Base.pricePerKg,newVolume)))`

to get a proper formatting we wrap the outcome in a function that ‘formats’ the output:

`[DB Sand].Filter( VolumeInKg <= _Volume.IfBlank([DB Sand].VolumeInKg.Min())).Last().WithName(Base,`

` `

` Quotient( _Volume , [DB Sand].VolumeInKg.Min()).RoundUp() * [DB Sand].VolumeInKg.Min().WithName(NewVolume, `

` `

`Product(Base.pricePerKg,newVolume))).WithName([Amount to pay],`

` `

` Format("$ {1}",[Amount to pay])`

` )`