Forum Discussion

samk_49's avatar
samk_49
New Member
2 years ago
Solved

How to overcome circular dependency while leveraging same measure?

I have a table that has Number of products in last 24 hrs column, Number of sold products and Number of products in inventory. I need to calculate Number of products.

 

Following is my table:

 Number of products in last 24 hrsNumber of sold productsNumber of products in inventory
2023-08-01100
2023-08-0351416
2023-08-0421522
2023-08-0841725
2023-08-113927
2023-08-1272226

 

I need to create a DAX query for Number of products measure

 

Desired result:

 Number of products in last 24 hrsNumber of sold productsNumber of products in inventoryNumber of products
2023-08-011001
2023-08-0351416(5-(14+16)+1) = -24
2023-08-0421522(2-(15+22)+(-24)) = -59
2023-08-0841725(4-(17+25)+(-59)) = -97
2023-08-113927(3-(9+27)+(-97)) = -130
2023-08-1272226(7-(22+26)+(-130)) = -171
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi samk_49 ,

    Please try to use this DAX to create a new column:

    Number of products = 
    CALCULATE(
        SUM(Sheet12[Number of products in last 24 hrs]) - SUM(Sheet12[Number of sold products]) - SUM(Sheet12[Number of products in inventory]),
        FILTER(
            'Sheet12',
            'Sheet12'[Date] < EARLIER(Sheet12[Date])
        )
    )
    + 'Sheet12'[Number of products in last 24 hrs] - 'Sheet12'[Number of products in inventory] - 'Sheet12'[Number of sold products]

    The final output is below:

     

    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi samk_49 ,

    Please try to use this DAX to create a new column:

    Number of products = 
    CALCULATE(
        SUM(Sheet12[Number of products in last 24 hrs]) - SUM(Sheet12[Number of sold products]) - SUM(Sheet12[Number of products in inventory]),
        FILTER(
            'Sheet12',
            'Sheet12'[Date] < EARLIER(Sheet12[Date])
        )
    )
    + 'Sheet12'[Number of products in last 24 hrs] - 'Sheet12'[Number of products in inventory] - 'Sheet12'[Number of sold products]

    The final output is below:

     

    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • samk_49 , Create a new measure using the current measure and try

     

    Sumx(Values(Records[Date]), [PrevProd_Test])

    • samk_49's avatar
      samk_49
      New Member

      My apologies Amit, your code worked well for originally posted question. But, I had to change my question to provide better clarity.