Forum Discussion

Nick1810's avatar
Nick1810
Frequent Visitor
6 years ago
Solved

Inventory Availability Coverage

Hello,

I have a table RK_InventarioHistorico like this:

 

ProductWarehouseQuantity
ACalifornia2
AMiami0
BCalifornia0
BMiami0
CCalifornia0
CMiami1
DCalifornia10
DMiami4

 

I want to know the percentage of the available items/products if at least I have 1 in stock in all the warehouses.

In this example, it should get this result:

 

Stock% Availability
Yes75%
No25%

 

This explains like this:

There are 4 products/items:

The total sum of  prodcut A is 2, so we have at least 1 unit in stock.

The total sum of  prodcut B is 0, so we DONT have at least 1 unit in stock.

The total sum of  prodcut C is 1, so we have at least 1 unit in stock.

The total sum of  prodcut D is 14, so we have at least 1 unit in stock.

 

We have 3 products where at least have 1 units in stock vs 4 items in total, so we have 75% of items available.

 

I need help getting this table with these measures:

 

Stock% Availability
Yes75%
No

25%

 

Thanks.

 

Nicolas.

  • Sorry I linked to the wrong file. The file is here:

    https://1drv.ms/u/s!Ancq8HFZYL_aiJBRfsmli39RRmqCOA?e=5Uo1n3 

    There is an Inventory table and a YesNo table. 

     

    Kind regards

    Djerro123

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

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Keep those thumbs up coming! 🙂

9 Replies

  • JarroVGIT's avatar
    JarroVGIT
    Resident Rockstar

    Fun question! I have created the following calculated table that results in what you want:

    Table 2 = 
    ADDCOLUMNS(DATATABLE("Stock", STRING, {{"Yes"}, {"No"}}), "% Available",
        VAR _tmpTable = SUMMARIZE(Inventory, Inventory[Product], "TotalInventory", SUM(Inventory[Quantity]))
        VAR _rowsOnStock = COUNTROWS(FILTER(_tmpTable, [TotalInventory] > 0))
        VAR _rowsNotOnStock = COUNTROWS(_tmpTable)-_rowsOnStock
        VAR _totalProducts = COUNTROWS(_tmpTable)
        RETURN
        IF([Stock] = "Yes", 
            DIVIDE(_rowsOnStock, _totalProducts), 
            DIVIDE(_rowsNotOnStock, _totalProducts)
        ))

    What this does is the following. DATATABLE creates a single column table with Yes and No rows. Then I add a column to it called "% Available". I then create a summarytable in memory of the Inventory table. This results in a table of two columns, one with Products and one with the sum of inventory of that product. Then I count the rows where inventory is 0 and where not. Finally, if the current row is "Yes" I divide rowsOnStock by totalProducts. If "No", I divide rowsNotOnStock by totalProducts.

    Result is this:

    Original valuesAdjusted formatting on the column to represent percentages

    Let me know if this suits your needs. If you want it to be dynamic (e.g. a table visual), then we need another aproach. 

     

     

    Kind regards

    Djerro123

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

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Keep those thumbs up coming! 🙂

    • JarroVGIT's avatar
      JarroVGIT
      Resident Rockstar

      I also created a solution based on measures (and a calculated table with just a Yes No column). PBIX can be found here (ignore other tables, they are for other questions)

      https://1drv.ms/u/s!Ancq8HFZYL_aiJA8RNb7RX-OsqnWrg?e=3va5Z1 

       

      Kind regards

      Djerro123

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

      If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

      Keep those thumbs up coming! 🙂

  • edhans's avatar
    edhans
    Community Champion

    I took the following approach. Note that this answers if you have stock in any warehouse, not all warehouses as you stated, but your results of 25%/75% seemed to indicate it was any warehouse.

     

    1) I created a simple table to get a Yes/No based on stock:

    Stock Status = 
    SUMMARIZE(
        Inventory,
        Inventory[Product],
        "On Hand",
            VAR IsInStock=
                CALCULATE(
                SUMX(
                    Inventory,
                    IF(Inventory[Quantity] > 0, 1, 0)
                )
                )
            RETURN
            IF(IsInStock > 0, "Yes","No")
    )

    It returns this table:

    Then I related that table to your inventory data as shown:

    Then I created a table visual, dropping in the "On Hand" field from the Stock Status table, and the Percent Available measure from the INventory Table, which is the following measure:

    Percent Available = 
    VAR ProductCount =
        COUNTROWS(
            DISTINCT( Inventory[Product] )
        )
    VAR TotalProductCount =
        COUNTROWS(
            ALL( Inventory[Product] )
        )
    RETURN
        DIVIDE(
            ProductCount,
            TotalProductCount,
            0
        )



     

    my PBIX file is here if you want to tinker with it.

    • Nick1810's avatar
      Nick1810
      Frequent Visitor

      Hi edhans,

       

      Thanks for the reply.

      Yes, the results are for ANY warehouse. I tried this, but I found I have another problem. Obviusly, the example was a simplification, but the reality is that the Inventory table is a History Inventory, so the Products are repeated for every month because it is a "picture" of the inventory at the end of each month. I use a Calendar Table to relate dates.

      The Inventory Table, in fact, looks like this:

       

      ProductWarehouseQuantityReport Date
      ACalifornia2ene-20
      AMiami0ene-20
      BCalifornia0ene-20
      BMiami0ene-20
      CCalifornia0ene-20
      CMiami1ene-20
      DCalifornia10ene-20
      DMiami4ene-20
      ACalifornia0dic-19
      AMiami0dic-19
      BCalifornia1dic-19
      BMiami0dic-19
      CCalifornia0dic-19
      CMiami0dic-19
      DCalifornia5dic-19
      DMiami9dic-19

       

      And the results I would like to get are these:

       

       On Hand
      DateYesNo
      ene-2075%25%
      dic-1950%50%

       

      Thanks!

       

      Nicolas.

       

       

       

      • edhans's avatar
        edhans
        Community Champion

        Well, that would have been very helpful to know up front. My model won't work as the product in the virtual table is no longer unique. I'd have to go back to the drawing board on this one. I'll see if I can play with it tonight.