Forum Discussion

ClaudioF's avatar
ClaudioF
Helper II
1 year ago
Solved

Impossible dax code sum

Hello, 

I've been here for a while trying to find out what was the problem with my dax code; i just found it, but its seems to be impossible of doing, i need the stock of the itemns to be distributed correctly following the order number order, from the lowest to the bigest. in the code i used, the problem is that when the  'DB_ORDERS'[Quant. Falta] <= StockAvailable is true, the sum will ocour, but its not right, i need a way to verify if the currend cumulated value of the sum is bigger than the current stock, if it is, it will not sum the current item quantity, and it will set the current item as out.. it seems to be impossible of doing this.. 

can anyone help?

 

file: https://1drv.ms/u/c/41783bdbd58abfd0/Ee4LSpTOV-pApa7mDD9DCAcBYoZEYqhFykemlsTpfg0jwQ?e=WlkIMu 

the code is: 

 

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 RunningStockVerify =
    SUMX(
        FILTER(
            ALLSELECTED('DB_ORDERS'),
            'DB_ORDERS'[Pedido] <= CurrentOrderNum &&
            'DB_ORDERS'[Quant. Falta] <= StockAvailable &&
            'DB_ORDERS'[Produto] = CurrentItem
        ),
        'DB_ORDERS'[Quant. Falta]
    )


VAR RunningStock =
    SUMX(
        FILTER(
            ALLSELECTED('DB_ORDERS'),
            'DB_ORDERS'[Pedido] <= CurrentOrderNum &&
            RunningStockVerify <= StockAvailable &&
            'DB_ORDERS'[Produto] = CurrentItem
        ),
        'DB_ORDERS'[Quant. Falta]
    )

//RETURN
//   RunningStockVerify


RETURN
    IF(
        MAX('DB_ORDERS'[Quant. Falta]) - RunningStockVerify <= 0 && RunningStock <> BLANK(),
        "available",
        "out"
    )
I have 21 of stock available, i need it to be distributed throught the marked itens
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hello ClaudioF ,

    Thank you for reaching out to the Microsoft Fabric Community.

     

    As lbendlin  has already mentioned, the data you provided is not entirely clear. However, based on my understanding of your scenario and the sample data available, I tried to replicate the issue and implement a solution accordingly.

     

    I have also attached the pbix file that I worked on for your reference. Kindly review it and let me know if it addresses your issue.

     

    If the solution does not meet your requirements, I would request you to please share a clear and simplified sample data along with the expected output. This will help us better understand the scenario and provide you with an accurate and effective solution.

     

    If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.

    Thankyou.



5 Replies

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello ClaudioF ,

    Thank you for reaching out to the Microsoft Fabric Community.

     

    As lbendlin  has already mentioned, the data you provided is not entirely clear. However, based on my understanding of your scenario and the sample data available, I tried to replicate the issue and implement a solution accordingly.

     

    I have also attached the pbix file that I worked on for your reference. Kindly review it and let me know if it addresses your issue.

     

    If the solution does not meet your requirements, I would request you to please share a clear and simplified sample data along with the expected output. This will help us better understand the scenario and provide you with an accurate and effective solution.

     

    If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.

    Thankyou.



    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi ClaudioF ,

      I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


      Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi @ClaudioF ,

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ClaudioF ,

     

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

     

    Thank you.