Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi everyone,
I'm currently facing some difficulty in generating a calculated column using DAX, whereas it's relatively straightforward using Excel.
1. Below is an image displaying a sample of the dataset I'm currently working with:
This dataset illustrates the inventory of two products. I'm attempting to monitor the remaining units after each shipment.
2. The new column, named "Quantity," is what I'm aiming to create using DAX.
3. Here is the simple Excel formula that achieves the desired output:
The logic needs to take into consideration there multiple items within Category, so it can't simply substract the shipment/ or add the stock replenishment from the above value, this is where I suspect the CategoryIndex will come in handy.
Ideally, I would prefer a solution in DAX. However, if it can be accomplished using M Code, I'm also open to suggestions.
Solved! Go to Solution.
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
WINDOW function (DAX) - DAX | Microsoft Learn
Quantity CC =
SUMX (
WINDOW (
1,
ABS,
0,
REL,
Data,
ORDERBY ( Data[CategoryIndex], ASC, Data[Date], ASC ),
,
PARTITIONBY ( Data[Category] ),
MATCHBY ( Data[CategoryIndex], Data[Date] )
),
Data[Stock Replenishment] + Data[Shipments]
)
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new column.
WINDOW function (DAX) - DAX | Microsoft Learn
Quantity CC =
SUMX (
WINDOW (
1,
ABS,
0,
REL,
Data,
ORDERBY ( Data[CategoryIndex], ASC, Data[Date], ASC ),
,
PARTITIONBY ( Data[Category] ),
MATCHBY ( Data[CategoryIndex], Data[Date] )
),
Data[Stock Replenishment] + Data[Shipments]
)
Thank you, this worked!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 5 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 22 | |
| 10 | |
| 9 | |
| 7 | |
| 6 |