Forum Discussion

giorgionway's avatar
giorgionway
Frequent Visitor
6 years ago
Solved

Price calculation from weight range

hello, is it possible  to calculate sales price (in yellow cell) from PRICES table?      
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi giorgionway ,

    First, you can create two calculated columns to get min weight and max weight of weight range:

    minWeight = value(left('Prices'[Weight Range], SEARCH("-",'Prices'[Weight Range])-1))
    maxWeight = value(mid('Prices'[Weight Range],SEARCH("-",'Prices'[Weight Range])+1,SEARCH("k",'Prices'[Weight Range])-2-SEARCH("-",'Prices'[Weight Range]) ))

    Then create a measure to get the corresponding price:

    sPrices = CALCULATE (
        MAX ( 'Prices'[Price] ),
        FILTER (
            'Prices',
            'Prices'[Company] = MAX ( 'Sales'[Company] )
                && 'Prices'[Level] = MAX ( 'Sales'[Level] )
                && 'Prices'[minWeight] <= MAX ( 'Sales'[Weight] )
                && 'Prices'[maxWeight] >= MAX ( 'Sales'[Weight] )
        )
    )

    Best Regards

    Rena