Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Dear friends,
I am working on a measure called 'remainingQuanity' that deducts the [Quantity] from [Inventory Units].
Sample table:
| Index | remainingQuantity | inventoryUnits | Quantity |
| 82078 | 3 | 4 | 1 |
| 82079 | 4 | 4 | -1 |
| 82080 | 3 | 4 | 1 |
| 82081 | 2 | 4 | 1 |
| 82082 | 1 | 4 | 1 |
| 82083 | 0 | 4 | 1 |
| 82084 | -1 | 4 | 1 |
| 82085 | -2 | 4 | 1 |
| 82086 | -3 | 4 | 1 |
| 82087 | -4 | 4 | 1 |
Once the [remainingUnits] becomes 0 it should use 0 instead of the calculation:
It's sound so easy, but what's the right dax?
Thank you
Solved! Go to Solution.
Hi @Powerwoman ,
ok, update:
I need this calculation to be done by item no.
Is that possible?
| Index | Item_No | inventoryUnits | Quantity |
| 82078 | 048454 | 4 | 1 |
| 82079 | 048454 | 4 | -1 |
| 82080 | 048454 | 4 | 1 |
| 82081 | 048454 | 4 | 1 |
| 82082 | 048454 | 4 | 1 |
| 82083 | 048454 | 4 | 1 |
| 82084 | 048454 | 4 | 1 |
| 82085 | 048454 | 4 | 1 |
| 82086 | 048454 | 4 | 1 |
| 82087 | 048454 | 4 | 1 |
| 82088 | 999999 | 4 | 1 |
| 82089 | 999999 | 4 | -1 |
| 82090 | 999999 | 4 | 1 |
| 82091 | 999999 | 4 | 1 |
| 82092 | 999999 | 4 | 1 |
| 82093 | 999999 | 4 | 1 |
| 82094 | 999999 | 4 | 1 |
| 82095 | 999999 | 4 | 1 |
| 82096 | 999999 | 4 | 1 |
| 82097 | 999999 | 4 | 1 |
Hi @Powerwoman
Another method, as calculated column
Hi @talespin,
this works fine, thank you.
Can it be done by item no as well?
| Index | Item_No | inventoryUnits | Quantity |
| 82078 | 048454 | 4 | 1 |
| 82079 | 048454 | 4 | -1 |
| 82080 | 048454 | 4 | 1 |
| 82081 | 048454 | 4 | 1 |
| 82082 | 048454 | 4 | 1 |
| 82083 | 048454 | 4 | 1 |
| 82084 | 048454 | 4 | 1 |
| 82085 | 048454 | 4 | 1 |
| 82086 | 048454 | 4 | 1 |
| 82087 | 048454 | 4 | 1 |
| 82088 | 999999 | 4 | 1 |
| 82089 | 999999 | 4 | -1 |
| 82090 | 999999 | 4 | 1 |
| 82091 | 999999 | 4 | 1 |
| 82092 | 999999 | 4 | 1 |
| 82093 | 999999 | 4 | 1 |
| 82094 | 999999 | 4 | 1 |
| 82095 | 999999 | 4 | 1 |
| 82096 | 999999 | 4 | 1 |
| 82097 | 999999 | 4 | 1 |
Hi @Powerwoman ,
Hi @talespin
Thanks for your solution.
The only 'bad' thing was that it killed my Power BI desktop because the original table had 90.000 rows.
My solution to this:
Different calculation of the 'running Total'
var _runningTotalQuantity =
sumx(
FILTER(
all(table),
table[Item_No] = EARLIER(table[Item_No]) &&
table[Index] <= EARLIER(table[Index])
),
table[Quantity]
)
hi @Powerwoman
90,000 shouldn't be a problem, if possible please share pbix file, removing any sensitive data.
Hi @talespin ,
great! That would be item no & index.
The table is already sorted this way.
Can it be grouped by item no and sorted by index?
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LearnAndPractise(Everyday) ) |
Hi @ThxAlot ,
it seems like this is working.
Can it be done by item no as well?
| Index | Item_No | inventoryUnits | Quantity |
| 82078 | 048454 | 4 | 1 |
| 82079 | 048454 | 4 | -1 |
| 82080 | 048454 | 4 | 1 |
| 82081 | 048454 | 4 | 1 |
| 82082 | 048454 | 4 | 1 |
| 82083 | 048454 | 4 | 1 |
| 82084 | 048454 | 4 | 1 |
| 82085 | 048454 | 4 | 1 |
| 82086 | 048454 | 4 | 1 |
| 82087 | 048454 | 4 | 1 |
| 82088 | 999999 | 4 | 1 |
| 82089 | 999999 | 4 | -1 |
| 82090 | 999999 | 4 | 1 |
| 82091 | 999999 | 4 | 1 |
| 82092 | 999999 | 4 | 1 |
| 82093 | 999999 | 4 | 1 |
| 82094 | 999999 | 4 | 1 |
| 82095 | 999999 | 4 | 1 |
| 82096 | 999999 | 4 | 1 |
| 82097 | 999999 | 4 | 1 |
@Powerwoman , Try using below method
RemainingQuantity =
CALCULATE(
SUMX(
FILTER(
ALL('YourTable'),
'YourTable'[Index] <= MAX('YourTable'[Index])
),
'YourTable'[Quantity]
),
FILTER(
ALL('YourTable'),
'YourTable'[Index] <= MAX('YourTable'[Index])
)
)
Please accept as solution and give kudos if it helps
Proud to be a Super User! |
|
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 11 | |
| 5 | |
| 5 |