Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
JustAThought
Frequent Visitor

Help With Cumulative Total

Good afternoon, I am trying to get a Cumulative Total to show based on ItemCode. Start with DataType="S" (for stock) and then if it is a S/O data type (deduct) or P/O Datatype (Increase) to show if the stock is increasing or decreasing with each order entry.  

I created this measure but it is not calculating properly

VAR CurrentDate = MAX('Append1'[Date])
VAR CurrentIndex = MAX('Append1'[Index])
VAR CurrentItemCode = MAX('Append1'[ItemCode])
RETURN
CALCULATE(
SUM('Append1'[QTY]),
FILTER(
ALLSELECTED('Append1'),
'Append1'[ItemCode] = CurrentItemCode &&
('Append1'[Date] < CurrentDate ||
('Append1'[Date] = CurrentDate && 'Append1'[Index] <= CurrentIndex))))

So I need it to start with the 77553.92 and then take that number and decrease by 2000, then take the new output and decrease by 4000. Not sure if this is possible or not. So I have one page that has a full view of every ItemCode, the user can then right click and drill through to their desired ItemCode and it will show this QTY column. 

 

Qty column is:

QTY

77553.92

-2000

-4000

-1000

-20000

20000

-2000

-20000

40000

-20000

-3000

-8000

-8000

-2000

-6000

1 ACCEPTED SOLUTION

Thank you for reaching back out, I found a resolution by doing a grouping and running total that way. I appreciate your time and efforts in trying to help me resolve this. 

View solution in original post

6 REPLIES 6
JustAThought
Frequent Visitor

Good morning, I was able to nearly get this fixed by doing this function in the advanced editor, however it is not working once the [UnitofMeasureConvFactor]>1. So I am still working through that. I was able to create a measure that accounts for it being >1 but the column is not subtracting the quantity from the output of that measure to continue the running total from there. 
GroupedTable = Table.Group(
#"Reordered Columns",
{"ItemCode"},
{
{"AllData", each
let
DataTable = _,
RunningTotalList = List.Accumulate(
DataTable[Qty],
{},
(state, current) => state & {if List.IsEmpty(state) then current else List.Last(state) + current}
),
AddRunningTotal = Table.FromColumns(
Table.ToColumns(DataTable) & {RunningTotalList},
Table.ColumnNames(DataTable) & {"RunningTotal"}
)
in
AddRunningTotal
}
}
)

 

Anonymous
Not applicable

Hi @JustAThought ,

I'm not clear about your requirement. The  [UnitofMeasureConvFactor] is a fact field or measure? Where the condition [UnitofMeasureConvFactor]>1 be applied? Could you please provide some sample data(exclude sensitive data) in your table 'Append1' (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And it is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Thank you for reaching back out, I found a resolution by doing a grouping and running total that way. I appreciate your time and efforts in trying to help me resolve this. 

Anonymous
Not applicable

Hi  @JustAThought ,

It's glad to hear that your problem has been resolved. Thanks for sharing your solution here. Could you please mark your post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours.  Thank you.

Best Regards

JustAThought
Frequent Visitor

here is an example of the table:  it is the QTYRunning I am trying to create

JustAThought_0-1717178033031.png

 

Anonymous
Not applicable

Hi @JustAThought ,

Assume that there is the field [Index] exist in the table 'Append1' and order the data by the field [DateType] (from S,S/O to P/O). You can update the formula of your measure [QTYRunning] as below:

QTYRunning =
VAR CurrentDate =
    MAX ( 'Append1'[Date] )
VAR CurrentIndex =
    MAX ( 'Append1'[Index] )
VAR CurrentItemCode =
    MAX ( 'Append1'[ItemCode] )
RETURN
    CALCULATE (
        SUM ( 'Append1'[QTY] ),
        FILTER (
            ALLSELECTED ( 'Append1' ),
            'Append1'[ItemCode] = CurrentItemCode
                && 'Append1'[Date] <= CurrentDate
                && 'Append1'[Index] <= CurrentIndex
        )
    )

If the above one can't help you figure out, please provide some raw data in your table 'Append1' (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And it is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors