Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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.

 

  • 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])

      

  • Hi,

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

    Hope this helps.

9 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    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

    • Anonymous's avatar
      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
      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        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])