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
Anonymous
Not applicable

Current Inventory Levels

I need to figure out a measure that calculates the current inventory level based on items last inventory entry into the table.  Below is an example of 5 items and to the right I flagged the last inventory date of each item.  The sum of the 5 items inventory on the last day they were inventoried is 12.  The result of the measure needs to be 12.

 

Curr Inventory Example Image.png

2 ACCEPTED SOLUTIONS

Bingo @Anonymous , that's great. Did the trick. Definitely some syntax errors and I missed an EARLIER. PBIX is attached.

 

 VAR __Table =
    ADDCOLUMNS(
      GROUPBY(
        'Table',
        [Item],
        "__LastDate",MAXX(CURRENTGROUP(),[Date])
      ),
      "__LastInventory",MAXX(FILTER('Table','Table'[Date] = [__LastDate] && 'Table'[Item] = EARLIER([Item])),'Table'[Qty])
    )
RETURN
  SUMX(__Table,[__LastInventory])

  



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Hi,

The answer should be 13 (not 12).  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Greg_Deckler
Community Champion
Community Champion

Well, no sample data posted as text so this DAX will likely have some syntax errors in it, but I am suuuuupppper bored because everthing is shut down with this COVID-19 stuff going on. Plus I realized this is a bit of a different pattern, although you could have still used that pattern. But something like this might be better:

 

Current Inventory Measure = 
  VAR __Table =
    ADDCOLUMNS(
      SUMMARIZE(
        'Table',
        [Item 1],
        "__LastDate",MAX([Date])
      ),
      "__LastInventory",MAXX(FILTER('Table','Table'[Date] = [__LastDate] && 'Table'[Item 1] = [Item 1],'Table'[Qty])
    )
RETURN
  SUMX(__Table,[__LastInventory])

 

Oh, and sample data posted as text is always great. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Is this helpful to test formula?

 

DateItemQty
3/2/2020Item 11
3/20/2020Item 12
3/19/2020Item 24
2/28/2020Item 21
3/1/2020Item 31
1/16/2020Item 40
2/21/2020Item 44
3/19/2020Item 43
12/6/2019Item 52
2/10/2020Item 52
3/21/2020Item 53

Hi,

The answer should be 13 (not 12).  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thx so much Ashish!!!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Bingo @Anonymous , that's great. Did the trick. Definitely some syntax errors and I missed an EARLIER. PBIX is attached.

 

 VAR __Table =
    ADDCOLUMNS(
      GROUPBY(
        'Table',
        [Item],
        "__LastDate",MAXX(CURRENTGROUP(),[Date])
      ),
      "__LastInventory",MAXX(FILTER('Table','Table'[Date] = [__LastDate] && 'Table'[Item] = EARLIER([Item])),'Table'[Qty])
    )
RETURN
  SUMX(__Table,[__LastInventory])

  



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @GR ,

 

Thanks for your solution. One additional question: how do you need to modify the syntax if your dataset has the mutation for each item: in other words, in ReynoldTstan's example, for item 4 you want to show the cumulative number (0+4+3=7) instead of the last one (3)?

 

Thanks a lot for your help in advance!

Anonymous
Not applicable

Awesome...thx Greg!!!

Greg_Deckler
Community Champion
Community Champion

Ha! I literally just wrote this quick measure today. This is the first time I get to use it! 🙂

https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814

 

That's the pattern, you will need to adapt it a bit. Let me know if you need further assistance in adapting it. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.