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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
pwagma
Regular Visitor

Fifo Stock cost - Multiple Tables & Products & Same dates

Hello

I have been reading a lot of articles about FIFO stock valuation. 
I have mainly followed the following one: https://radacad.com/dax-inventory-or-stock-valuation-using-fifo.

 

The particular situation I have is that I have 2 different tables. One for the sales operations and one for the buy operations.

To solve the only 1 operation per day limit, I used an index column in each table.

 

No the problem is where I calculate the FIFO column. When I declare the variable it is not accepted and I have different errors.

 

FIFO = 
VAR myCurrentSell = Hoja1[Cantidad Acumulada]
VAR myLastSell = Hoja1[Cantidad acumulada anterior]
VAR mySymbol = Hoja1[Artículo]
VAR myCumulativeBuy = FIRSTNONBLANKVALUE(Transferencias[Kg Acumulados],FILTER(Transferencias, mySymbol))
VAR myLastCumulativeBuy = FIRSTNONBLANKVALUE(Transferencias[Kg Acumulados Anteriores],FILTER(Transferencias, mySymbol))
VAR FIFOFilterTable =
    FILTER (
        Transferencias,
        Transferencias[Producto] = mySymbol
            && ( ( Transferencias[Kg Acumulados] >= myLastSell
            && Transferencias[Kg Acumulados] < myCurrentSell )
            || Transferencias[Kg Acumulados] >= myCurrentSell
            && Transferencias[Kg Acumulados Anteriores] < myCurrentSell
            || Transferencias[Kg Acumulados Anteriores]  > myLastCumulativeBuy
            && Transferencias[Kg Acumulados] < myLastCumulativeBuy )
    )
VAR FilteredFIFOTable =
    ADDCOLUMNS (
        FIFOFilterTable,
        "New Value", SWITCH (
            TRUE (),
            Transferencias[Kg Acumulados] > myLastSell
                && Transferencias[Kg Acumulados Anteriores] < myLastSell, Hoja1[cantidad]
                - ( myLastSell - Transferencias[Kg Acumulados Anteriores] ),
            Transferencias[Kg Acumulados] < myCurrentSell, Hoja1[cantidad],
            -- ELSE --
            Hoja1[cantidad]
                - ( Transferencias[Kg Acumulados] - myCurrentSell )
        )
    )
RETURN
    Related(Transferencias[Costo Total])
        - SUMX ( FilteredFIFOTable, [New Value] * related(Transferencias[Costo Unitario])
)

The column fifo is made on the "Sales" table. (Of course I need to know the cost of each sale).

When I declare the variable mycumulativebuy and mypreviouscumulativebuy, it doesn't recognize the relationship with the other table. I tried to use other ways to declare it (hence the function that you can see in the code) but the error it comes is "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

 

I appreciate your help

Thanks

pablo

 

 

1 REPLY 1
Anonymous
Not applicable

Hello @pwagma ,
You may try
myCumulativeBuy = 
Firstnonblankvalue(Transferencias[kg acumulados], Filter(Transferencias, Transferencias = mysymbol))

Can you please provide the sample data and expected output?

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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