Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
alex9999
Helper I
Helper I

Filter CALCULATE SUM by 2 string columns

Hi,

 

I am trying to create an inventory management system in Power BI to track materials moving through a unit. I need to be able to create measures for every single item that is available to be moved.

 

I will need to calculate the sum of the "quantity" that is being moved "IN", once I do that, I can do the same for the material moving "OUT", leaving me with a final figure for the current number of an item which is in the unit.

 

I need to FILTER by the "Item" and then filter by "Material IN", which are both strings.

 

Here is what I've tried so far:

 

Calculate IN = CALCULATE(SUMX('Inventory', 'Inventory'[Quantity]),FILTER (
        ALL ( 'Inventory' ),
        SEARCH ( "Standard 1.00m Spigot", 'Inventory'[Item],) > 0
            && SEARCH ( "In", 'Inventory'[material_InOut_Checkbox],) > 0
    )
)

 

 

 

IN Standard 1.00m Spigot = CALCULATE(SUM('Inventory'[Quantity]), FILTER('Inventory', 'Inventory'[Item] = "Standard 1.00m Spigot"), FILTER('Inventory', 'Inventory'[material_InOut_Checkbox] = "In"))

 

Here is a sample data set for you to use:

Assuming each "Item" starts with 1000.

 

Material IN/OUTItemQuantity
InStandard 1.00m Spigot3
OutStandard 1.00m Spigot10
In Standard 1.00m Spigot5

 

There will be 998 Standard 1.00m Spigot's in the unit. 

 

There will be over 50 items to record so I will need to filter by each one to get an exact figure for the item's count in the unit.

 

Thanks in advance 🙂

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @alex9999 , would you consider the following for your Inventory Management solution:

 

DateTimeActionItem KeyQuantity
01/01/2022 00:00Stocktake110
15/01/2022 12:23In13
16/01/2022 17:23Out1-10
20/01/2022 11:23In15
01/02/2022 00:00Stocktake17
15/02/2022 12:23In13
16/02/2022 17:23Out1-10
20/02/2022 11:23In15

 

The features of this approach is that In and Out quantity movements are assigned + and - sign accordingly, so it make summing to find the current Inventory quantity much easier.  The second feature is the addition of the Stocktake action.  This allows you to reset your inventory without reporting as In and Out.  This could make it easier to track missing quantity or incorrect In/Out records.

 

Note you should create a Item table.  This table will have the Item Key (primary) and Item details.  You can also add a calculated column with the current quantity using the following DAX expression (note this is the quantity at point of time the model is refreshed):

 

Current Item Quantity = //Calculated Column for Item table
VAR _LastStocktake = SUMMARIZE( FILTER(Inventory, Inventory[Action] = "Stocktake") , "Last Stocktake", MAX(Inventory[DateTime]))
VAR _StockMovementsSinceLastStockTake = CALCULATE( SUM(Inventory[Quantity]) , Inventory[DateTime] >= _LastStocktake )
RETURN
_StockMovementsSinceLastStockTake

DarylLynchBzy_0-1645536125489.png

 

From a measure perspective, the following allows you to show stock levels over time:

 

 

Daily Stock Level =
//Measure
VAR _Test =
    ISFILTERED ( 'Item'[Item Key] )
VAR _Date =
    MIN (
        MIN ( 'Calendar'[Date] ),
        TODAY ()
    )
VAR _LastStocktake =
    SUMMARIZE (
        FILTER (
            Inventory,
            Inventory[DateTime] <= _Date
                && Inventory[Action] = "Stocktake"
        ),
        "LastStockTake", MAX ( Inventory[DateTime] )
    )
RETURN
    IF (
        _Test,
        CALCULATE (
            SUM ( Inventory[Quantity] ),
            Inventory[DateTime] >= _LastStocktake,
            Inventory[DateTime] <= _Date
        ),
        "No Result"
    )

Note the Isfilter stops the measure from calculating when the item is not filtered

DarylLynchBzy_1-1645537604532.png

 

 

 

View solution in original post

1 REPLY 1
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @alex9999 , would you consider the following for your Inventory Management solution:

 

DateTimeActionItem KeyQuantity
01/01/2022 00:00Stocktake110
15/01/2022 12:23In13
16/01/2022 17:23Out1-10
20/01/2022 11:23In15
01/02/2022 00:00Stocktake17
15/02/2022 12:23In13
16/02/2022 17:23Out1-10
20/02/2022 11:23In15

 

The features of this approach is that In and Out quantity movements are assigned + and - sign accordingly, so it make summing to find the current Inventory quantity much easier.  The second feature is the addition of the Stocktake action.  This allows you to reset your inventory without reporting as In and Out.  This could make it easier to track missing quantity or incorrect In/Out records.

 

Note you should create a Item table.  This table will have the Item Key (primary) and Item details.  You can also add a calculated column with the current quantity using the following DAX expression (note this is the quantity at point of time the model is refreshed):

 

Current Item Quantity = //Calculated Column for Item table
VAR _LastStocktake = SUMMARIZE( FILTER(Inventory, Inventory[Action] = "Stocktake") , "Last Stocktake", MAX(Inventory[DateTime]))
VAR _StockMovementsSinceLastStockTake = CALCULATE( SUM(Inventory[Quantity]) , Inventory[DateTime] >= _LastStocktake )
RETURN
_StockMovementsSinceLastStockTake

DarylLynchBzy_0-1645536125489.png

 

From a measure perspective, the following allows you to show stock levels over time:

 

 

Daily Stock Level =
//Measure
VAR _Test =
    ISFILTERED ( 'Item'[Item Key] )
VAR _Date =
    MIN (
        MIN ( 'Calendar'[Date] ),
        TODAY ()
    )
VAR _LastStocktake =
    SUMMARIZE (
        FILTER (
            Inventory,
            Inventory[DateTime] <= _Date
                && Inventory[Action] = "Stocktake"
        ),
        "LastStockTake", MAX ( Inventory[DateTime] )
    )
RETURN
    IF (
        _Test,
        CALCULATE (
            SUM ( Inventory[Quantity] ),
            Inventory[DateTime] >= _LastStocktake,
            Inventory[DateTime] <= _Date
        ),
        "No Result"
    )

Note the Isfilter stops the measure from calculating when the item is not filtered

DarylLynchBzy_1-1645537604532.png

 

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.