Forum Discussion

JustAThought's avatar
JustAThought
Frequent Visitor
2 years ago
Solved

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

  • 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. 

6 Replies

  • JustAThought's avatar
    JustAThought
    Frequent Visitor

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

     

    • Anonymous's avatar
      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

  • JustAThought's avatar
    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's avatar
      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

      • JustAThought's avatar
        JustAThought
        Frequent Visitor

        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.