cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Calculate Stock balance for multiple transactions per date

Hi guys, i'm having trouble cracking this one. The formula works fine until i get 2 or more transactions on the same date:

pabsmart_3-1599403569516.png

So the balance as at March should be 17 but my formula as above gets to 32. I have tried several variation with LASTNONBLANK or LASTNONBLANKVALUE but couldn't make it work. Thanks, appreciated it. 

Pablo

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

@pabsmart - You are going to need something to tell Power BI which one is "later". Perhaps you can add an Index to your data and that will resolve the date ties? You could then replace your LASTDATE() with MAX([Index])


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




View solution in original post

6 REPLIES 6
Highlighted
Super User IV
Super User IV

@pabsmart - You are going to need something to tell Power BI which one is "later". Perhaps you can add an Index to your data and that will resolve the date ties? You could then replace your LASTDATE() with MAX([Index])


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




View solution in original post

Highlighted

Thanks @Greg_Deckler  but i get the following error just adding MAX to the calculate statement: 

 

pabsmart_0-1599436495634.png

 

Thanks for your help again, 

 

Highlighted

@pabsmart ,

 

Max(Table[Index]) will not work

you have taken like

Filter(Table, Table[Index] = max(Table[Index]))

 

or try lastnonblankvalue(Table[index], Sum(Table[Actual Quantity))

https://www.linkedin.com/pulse/five-recent-power-bi-functions-you-should-use-more-often-amit-chandak



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted

@pabsmart - You need more of a filter statement in your CALCULATE versus just a scalar value for your filter. If you can post sample data and expected result that would be best.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




Highlighted

// If you have an Index column that
// establishes the order of events...

[Stock By Code] =
calculate(
    sum( Inventario[Actual Quantity] ),
    lastnonblank(
        Inventario[Index],
        1
    )
)
Highlighted

Thanks a lot @Greg_Deckler . I have solved the calculation with this formula:

 

Stock by Code =
Var MaxIndex = MAX(Inventario[Index])
RETURN
CALCULATE(SUM(Inventario[Cant. Actual]),LASTDATE(Inventario[Fecha]),FILTER(Inventario,[MaxIndex] = MaxIndex))
 
Cheers,
Pablo

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors