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
mtrevisiol
Helper V
Helper V

Get the previous value calculated with ALLEXCEPT

Hi everyone. I've got this table:

 

mtrevisiol_2-1633515290663.png

 

  • ProdID is the key: it represents the production order
  • Date represents the date. In this case from 28th to 30 september
  • Product is the name of the product
  • Total Qty is the total number of pieces that must be produced in the current production order
  • Produced Pieces is the quantity produce. It represents to which point we are with the production: it is a value that is increased as pieces are produced
  • MaxProducedPiecesToday represents the total quantity produced in each date, and it is calculated as the maximum of ProducedPieces for each date, using ALLEXCEPT, as explained in the picture

My purpose is to calculate the number of Pieces Produced Today, given by the maximum of pieces produced today minus the maximum of pieces produced in the previous date, that might not be the day immediately preceding.

 

Can you help me? Thanks in advance. Here is the PBIX file: https://www.dropbox.com/s/2h9avwap7xy2qw1/Production%20order.pbix?dl=0

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

This should get you the value from the previous date.  You can then work out the subtraction. Please test with more products and different date setups.

NewColumn = VAR _prodID = Query[ProdID]
VAR _date = Query[Date]
VAR _fromDate = CALCULATE(MAX(Query[Date]), FILTER(Query, Query[Date] < _date  && Query[ProdID] = _prodID))

RETURN
CALCULATE(MAX(Query[MaxProducedPcsToday]), FILTER(Query, Query[Date] = _fromDate && Query[ProdID] = _prodID))

 

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

This should get you the value from the previous date.  You can then work out the subtraction. Please test with more products and different date setups.

NewColumn = VAR _prodID = Query[ProdID]
VAR _date = Query[Date]
VAR _fromDate = CALCULATE(MAX(Query[Date]), FILTER(Query, Query[Date] < _date  && Query[ProdID] = _prodID))

RETURN
CALCULATE(MAX(Query[MaxProducedPcsToday]), FILTER(Query, Query[Date] = _fromDate && Query[ProdID] = _prodID))

 

Thanks for help @HotChilli 

I did it by creating this column:

Max precedente =
var max_precedente = CALCULATE (
   MAX ( Query[ProducedPcs] ),
   FILTER (
      ALL ( Query ),
      Query[Date] < EARLIER ( Query[Date] ) && Query[MOId] = EARLIER(Query[ProdID])
      )
)
RETURN IF(max_precedente>0, max_precedente, 0)

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.