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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
}
}
)

 

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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. 

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
JustAThought
Frequent Visitor

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

JustAThought_0-1717178033031.png

 

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.