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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
rodrigoestrella
Frequent Visitor

sum quantities over different time periods

Hello ! 

I have to calculate stock adjustments over sales in several stores of a supermarket in the period between the last stock count and today. The thing is that the stock count date is different for each store, and I would also like to decompose the adjustments by product category. 

I managed to make a measure that calculates them, but when I want to calculate the ratio aggregated by location the measure is not working.

The data looks like this

store_id  adjustment_date  product_id  adjustmentCause_id    Quantity  amount
22020/08/206331$3.00
 
The stock date table has two columns store_id and stock_date. And the sales table looks like this.
store_id  date  product_id  Quantity  amount
22020/08/206312$36.00
 

The measures I managed to do are this ones.

adjusment = CALCULATE(SUM(merms[amount]), FILTER('Datetable', 'Datetable'[date] > MAX(Stock_date[store_stockdate])))
sales = CALCULATE(SUM(sales[sales_amount]), FILTER('Datetable', 'Datetable'[date] > MAX(Stock_date[store_stockdate])))
ratio = DIVIDE([adjustment], [sales], 0 )
The thing is that when I aggregate by location the date that the measures uses is the max of the stock dates of the stores in that location, not the one that corresponds to each store.
I would really appreciate if you can help me out. Thanks in advance !
Rodrigo
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@rodrigoestrella, try this measure:

 

Adjustments = 
SUMX (
    Merms,
    IF ( Merms[adjustment_date] >= RELATED ( DimStore[stock_date] ), Merms[amount] )
)

 

Data model:

 

DataInsights_0-1599164186962.png

 

By store_id:

 

DataInsights_1-1599164237838.png

 

By location:

 

DataInsights_2-1599164265316.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@rodrigoestrella, try this measure:

 

Adjustments = 
SUMX (
    Merms,
    IF ( Merms[adjustment_date] >= RELATED ( DimStore[stock_date] ), Merms[amount] )
)

 

Data model:

 

DataInsights_0-1599164186962.png

 

By store_id:

 

DataInsights_1-1599164237838.png

 

By location:

 

DataInsights_2-1599164265316.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks a lot !!!!! It worked perfectly !!

Thanks a lot !!!!! It worked perfectly !!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.