Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
francoisl
Helper II
Helper II

'Bucketing' sales in price matrix.

Hi all, 

 

I need to bucket sales in a price matrix.   The price matrix has discounts upon unit sold.  I am currently ignoring date, product tables for the sake of clarity but if we need them please feel free to add them in the explanation.

Here`s a simple example.

 

Price Grid table with break (imported table)

 

ProductLevelFROMTOUNIT PRICE
A101010.00
A211208.50
A3219999997.75
B101545.00
B21699999937.00
D1099999925.00

 

Sales Table with qty ordered (imported table) 

INVOICEPRODUCTQTYUNIT PRICE
1A310.00
2D4525.00
3C312.00
4A158.50
5A178.50
6B745.00
7B945.00

 

Desired Results

ProductLevelFROMTOUNIT PRICEQTYSOLD
A101010.003
A211208.5032
A3219999997.750
B101545.0016
B21699999937.000
D1099999925.0045

 

My challenge here is that I do not want to use the price because there is always a good business reason to change the price on an order. Quantity should be the driver to bucket those sales.   Of course the level is not on the sales table... that would have been to easy. 

Product C is not in the price grid and should not appear in the desired result. If nothing was sold then we need to show 0.

999999 is always the upper value of the last level even if there is only one level.  

 

I am struggling with the lookupvalue or the firstnonblank on the sales table but I do not think this is the right way to do this.  I will try related dax command but currently any comments are welcome. 

 

 

Many thanks


François 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @francoisl ,

You can update the measure "QTYSOLD " as below:

QTYSOLD =
CALCULATE (
SUM ( 'Sales'[QTY] ),
FILTER (
'Sales',
'Sales'[PRODUCT] = MAX ( 'Price'[Product] )
&& 'Sales'[QTY]>=MAX('Price'[FROM])
&&'Sales'[QTY]<=MAX('Price'[TO])
)
) + 0

Best Regards

Rena

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @francoisl ,

You can create two measures as below:

QTYSOLD = 
CALCULATE (
    SUM ( 'Sales'[QTY] ),
    FILTER (
        'Sales',
        'Sales'[PRODUCT] = MAX ( 'Price'[Product] )
            && 'Sales'[UNIT PRICE] = MAX ( 'Price'[UNIT PRICE] )
    )
) + 0
Measure = 
SUMX (
    VALUES ( 'Price'[Product] ),
    SUMX ( VALUES ( 'Price'[Level] ), [QTYSOLD] )
)

'Bucketing' sales in price matrix.JPG

Best Regards

Rena

Hi all, 

 

I was specifically looking for a solution that uses an the interval and not the price. 

 

Thanks I will keep looking for a specific solution. 

 

F

Anonymous
Not applicable

Hi @francoisl ,

You can update the measure "QTYSOLD " as below:

QTYSOLD =
CALCULATE (
SUM ( 'Sales'[QTY] ),
FILTER (
'Sales',
'Sales'[PRODUCT] = MAX ( 'Price'[Product] )
&& 'Sales'[QTY]>=MAX('Price'[FROM])
&&'Sales'[QTY]<=MAX('Price'[TO])
)
) + 0

Best Regards

Rena

Looks like the above solutions are pretty close.

Add a column to PriceGrid table like this :

ColQTYSOLD = CALCULATE(SUM(SalesTable[QTY]), FILTER(SalesTable, SalesTable[PRODUCT] = PriceGrid[PRODUCT]  && SalesTable[QTY]  >= PriceGrid[FROM] && SalesTable[QTY] <= PriceGrid[TO])) + 0

 

amitchandak
Super User
Super User

@francoisl , you can get a new column in price grid table like

 

QTYSOLD = sumx(filter(Sales, sales[PRODUCT]=PriceGrid[PRODUCT] &&sales[UNIT PRICE]=PriceGrid[UNIT PRICE] ), sales[QTY])

 

You can also use sales[UNIT PRICE]>=PriceGrid[from] from && sales[UNIT PRICE]< =PriceGrid[to]  in place of  sales[UNIT PRICE]=PriceGrid[UNIT PRICE]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (4,687)