Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I'm attempting to write a formula that decrements inventory in a column based on demand and qty available. In the attached picture, column c is being decremented in column d, incrementally, based on the number of occurrences in column b.
Solved! Go to Solution.
You need some sort of index or other sortable column that indicates the order of these events. Otherwise, if the column isn't in this exact order (which is not guaranteed by the DAX engine), you'll get results that don't make sense.
Once you have that index set up, you can simplify this math down to subtracting a count of the rows from this table where the index/sorting column is less than the current index from the initial stock qty.
Also, are you setting this up as a measure, or a calculated column? I would suggest changing your set up and creating this up as a measure, but here's the DAX for a calculated column, since that looks like what you're creating.
QTY_REMAINING = 'Table'[stock qty] - CALCULATE(COUNTROWS('Table'), FILTER(ALLEXCEPT('Table', 'Table'[unit], 'Table'[part needed]), 'Table'[Index] <= EARLIER('Table'[Index]))
You need some sort of index or other sortable column that indicates the order of these events. Otherwise, if the column isn't in this exact order (which is not guaranteed by the DAX engine), you'll get results that don't make sense.
Once you have that index set up, you can simplify this math down to subtracting a count of the rows from this table where the index/sorting column is less than the current index from the initial stock qty.
Also, are you setting this up as a measure, or a calculated column? I would suggest changing your set up and creating this up as a measure, but here's the DAX for a calculated column, since that looks like what you're creating.
QTY_REMAINING = 'Table'[stock qty] - CALCULATE(COUNTROWS('Table'), FILTER(ALLEXCEPT('Table', 'Table'[unit], 'Table'[part needed]), 'Table'[Index] <= EARLIER('Table'[Index]))
That worked perfectly. Thanks so much!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |