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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ClaudioF
Helper I
Helper I

cant find the problem in code

Hi everybody

This porblem is driving me crazy, i have two dashboards with the same dax codes, the thing is, in one it works properly, in the other it does not and i just can't find out why. the dashboards: the one with problem (ControleDaProducaoMaisLeve&BALSendDistribui.pbix) the working one (Sum interval considering many filters11101.pbix)

The logic is, the stock might be distributed properly through the orders in a whay that it goes first to the oldest to the newest order, and if the order quantity is bigger than the left stock after distributed to the anterior, it will verify the next order and if the quantity os the remaing stock is enought to the order need, it will be used. see in image below:

 

Captura de tela 2025-03-06 200914.png

 

the marked in green is what it should be, i have 72 of this item in stock and it should be enought to the orders 111, 222, 444 and 555.

 

Please anyone help me, i totaly can't find the problem, one works and the other just does not..

 

 

Thankyou all.

3 REPLIES 3
ClaudioF
Helper I
Helper I

Just to add info, i have just tried some tests and, i am not sure, but it seems that when i work with a external data source or and excel file, the result was wrong, i dont know if its even possible that something like that caan interfer in the result, i just ajusted all the columns with its correct data type.. i still dont know what difference between the two dashboards is cousing the problem..

v-cgao-msft
Community Support
Community Support

Hi @ClaudioF ,

 

Please try:

ItemStatus = 
VAR CurrentItem =
    SELECTEDVALUE ( DB_ORDERS[Produto] )
VAR CurrentOrderNum =
    SELECTEDVALUE ( DB_ORDERS[Pedido] )
VAR StockAvailable =
    CALCULATE (
        SUM ( 'Table Estoq'[Estoque Real] ),
        'Table Estoq'[Produto] = CurrentItem
    )
VAR RunningStock =
    CALCULATE (
        SUM ( 'DB_ORDERS'[Quant. Falta] ),
        FILTER (
            ALLSELECTED ( 'DB_ORDERS' ),
            'DB_ORDERS'[Produto] = MAX ( 'DB_ORDERS'[Produto] )
                && 'DB_ORDERS'[Data Limite] <= MAX ( 'DB_ORDERS'[Data Limite] )
        )
    )
RETURN
    IF (
        RunningStock <= StockAvailable
            && MAX ( DB_ORDERS[Quant. Falta] ) <= StockAvailable,
        "available",
        "out"
    )

vcgaomsft_0-1741315500856.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hello @v-cgao-msft thankyou for the repply; i tried this code and it works as you showed, alghthou, its considering the date insteat of the order num to determn if the order is older or not, the thing with the date is that there can be many orders with the same date, bust the number of the order will really show which is the the first in line;

 

Did you see the working dashboard? it totally works with the same dax code, using the same logic, considering the order num, i did the same things to the other dashboard but it didnt work.. what could be the problem?

Helpful resources

Announcements