Forum Discussion

jhaanand81's avatar
jhaanand81
Frequent Visitor
4 years ago
Solved

Subtotal of Negative Values

Hi,   Please help me with subtotal of negative value in single row and adding it with a positive value without splitting the row Amount 27733.51 -6201900.18 6177381.24 -77460.65 96...
  • jhaanand81's avatar
    4 years ago

    Hi  Nathaniel,

     

    Thank you for your reply please find the details and let me know if you are able to understand my query.

    Yes need to split the single to get the output.

     

    Document DateAmount in doc. curr.Subtotal Positive Values(Amount in doc. curr.)  more than 1 Output 1Total of Value(Amount in doc. curr.) less than 0 Output 2Total of Negative Value(-16197615.03+Subtotal of Positive Value) Output 3
    31-10-202127733.51 -6201900.18-16169881.52
    31-10-2021-6201900.18 -77460.65-9992500.28
    31-10-20216177381.24 -164075.37-9896376.28
    30-09-2021-77460.65 -164075.37-9732154.28
    23-09-202196124 -164075.37-9567932.28
    01-10-2021-164075.37 -107457.97-9403710.28
    24-09-2021164222 -127615.96-9296156.28
    01-10-2021-164075.37 -34430.54-9168426.28
    24-09-2021164222 -153512.81-9133961.28
    01-10-2021-164075.37 -163591.81-8980311.28
    24-09-2021164222 -92810.06-8816573.28
    01-10-2021-107457.97 -298319.41-8723680.28
    24-09-2021107554 -184541.08-8425094.28
    01-10-2021-127615.96 -164510.98-8240388.28
    24-09-2021127730 -127596.97-8075730.28
    04-10-2021-34430.54 -216945.13-7948019.28
    27-09-202134465 -124299.92-7730880.28
    04-10-2021-153512.81 -88004.36-7606469.28
    27-09-2021153650 -125634.73-7518386.28
    04-10-2021-163591.81 -23637.34-7392639.28
    27-09-2021163738 -98490.41-7368978.28
    04-10-2021-92810.06 -64018.92-7270389.28
    27-09-202192893 -171185.02-7206306.28
    04-10-2021-298319.41 -114399.77-7034968.28
    27-09-2021298586 -99440.14-6920466.28
    04-10-2021-184541.08 -119750-6820937.28
    27-09-2021184706 -49491-6701080.28
    04-10-2021-164510.98 -140522-6651539.28
    27-09-2021164658 -113436-6510891.28
    04-10-2021-127596.97 -82038-6397354.28
    27-09-2021127711 -153218.08-6315243.28
    04-10-2021-216945.13 -133116.04-6161888.28
    27-09-2021217139 -49595.68-6028653.28
    04-10-2021-124299.92 -392974.82-5979013.28
    27-09-2021124411 -152298.9-5585687.28
    04-10-2021-88004.36 -132026.02-5433254.28
    27-09-202188083 -148817.01-5301110.28
    04-10-2021-125634.73 -155374.15-5152160.28
    27-09-2021125747 -99440.14-4996647.28
    04-10-2021-23637.34 -166459.24-4897118.28
    27-09-202123661 -102597.31-4730510.28
    05-10-2021-98490.41 -138842.92-4627821.28
    28-09-202198589 -146134.72-4488854.28
    05-10-2021-64018.92 -131258.7-4342573.28
    28-09-202164083 -130762.14-4211197.28
    05-10-2021-171185.02 -75018.96-4080318.28
    28-09-2021171338 -45141.81-4005232.28
    05-10-2021-114399.77 -158252.58-3960045.28
    28-09-2021114502 -176340.41-3801649.28
    05-10-2021-99440.14 -14583.97-3625151.28
    28-09-202199529 -32748.22-3610554.28
    12-10-2021-119750 -3605345.94-3577773.28
    05-10-2021119857  -3397625.28
    12-10-2021-49491  179987.15
    05-10-202149541   
    12-10-2021-140522   
    05-10-2021140648   
    12-10-2021-113436   
    05-10-2021113537   
    12-10-2021-82038   
    05-10-202182111   
    16-10-2021-153218.08   
    08-10-2021153355   
    16-10-2021-133116.04   
    08-10-2021133235   
    16-10-2021-49595.68   
    08-10-202149640   
    18-10-2021-392974.82   
    11-10-2021393326   
    19-10-2021-152298.9   
    12-10-2021152433   
    19-10-2021-132026.02   
    12-10-2021132144   
    20-10-2021-148817.01   
    13-10-2021148950   
    20-10-2021-155374.15   
    13-10-2021155513   
    25-10-2021-99440.14   
    18-10-202199529   
    25-10-2021-166459.24   
    18-10-2021166608   
    25-10-2021-102597.31   
    18-10-2021102689   
    25-10-2021-138842.92   
    18-10-2021138967   
    25-10-2021-146134.72   
    18-10-2021146281   
    27-10-2021-131258.7   
    20-10-2021131376   
    27-10-2021-130762.14   
    20-10-2021130879   
    27-10-2021-75018.96   
    20-10-202175086   
    27-10-2021-45141.81   
    20-10-202145187   
    29-10-2021-158252.58   
    22-10-2021158396   
    29-10-2021-176340.41   
    22-10-2021176498   
    29-10-2021-14583.97   
    22-10-202114597   
    29-10-2021-32748.22   
    22-10-202132781   
    25-10-2021180148   
    31-10-2021-3605345.94   
    31-10-20213577612.43   
    31-10-202124518.94   
    25-10-202195548   
    25-10-2021116893   
    25-10-2021182577   
    26-10-2021281997   
    27-10-2021133627   
    27-10-2021120197   
    27-10-2021151009   
    27-10-202199529   
    27-10-20212762   
    27-10-2021121188   
    27-10-2021172152   
    27-10-2021161734   
    27-10-2021124411   
    27-10-2021156379   
    27-10-202143792   
    28-10-2021141123   
    28-10-2021127334   
    28-10-2021183513   
    28-10-2021298586   
    28-10-2021281997   
    28-10-2021130535   
    28-10-2021111337   
    28-10-202188731   
    29-10-2021225678   
    30-10-202128198   
  • v-yingjl's avatar
    v-yingjl
    4 years ago

    Hi jhaanand81 ,

    Based on your description, you can try this query:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZdJduQwCEDvknVKj3k4S17uf42m2rJLsul17/IgX4wG6ufni/GF8CIg/Pr+Infmofj1+33TvIwAE2BgPJWGxQUOkkMHL8gLdBeDYfpXRbyo0nASsJlCE3Ad7AciC1IqIvqfDLioj+yYekzbeMgNdaQ1zDvjcDCyMizCMOZz5AtSmpnMnUBlRRqBT6RUpp0VNNbEnjGumjZMUiAMsCdSmuSGoAzGHNJYKZWGdZ6FqOCAaDwLcWgZEy3XsmOsktZFUwXQtKuefqsNYhcPWooO5CYedORs7QhljqTOjkhrJwJABjeZLk10mUZSYxneeFYqF++i4ar04KbTSmPTL906ICThKmesHVDVzIaoDw3jCn4lSnNGshGVRwwd0CDvFJ+duTMoXDl2bxgUnW/dYkmRGmrSxJJKRyxIu5X082Nanyp5qDeApGSTRkmdKby9L6DUuFpyk2gdYplNcnOIlTuHgqDLXxDONkS7DRaq6s1PEWI1ocyqHcOMaAOkYZiJO6YSkjqsMSNZbXIQq/jFSeky4sgWrkOXs8wcScHco6EaOqOpbGmEuUO4/rKzF3emUiOzeWCvYgT6gJlQ3goZORvoxmjVSwZqw6jqOW/+3b9bdj79uxNoNSbz3NUbUio7J+7OAGnWkMCGqdREa4cjhM6Pfmc40rxjxPA9vzpGjD57arNToy2GPxNaGnZrEXCj66vfGQjPhqlv/j3C7ImUJjortYzks1tXojQx/b31ZpDSmIuK9uYMPo3vjNfE/0zjjXGTcxnujNRr187bkGqNzjMmlxhzLG1Eac4Qt+ETgNKcii82UK7tmfJUsnpdSjSEnzp6J+2kNlNZV1fTtDV/znPk5lltwhnjOn+qu/JzBmzzyqiTvw/iTl43CDQdtHyPq7huQ+oer/UXjdypxlQjrxP8s8LXd67b4uZkLf3GGynptXLXtkAkbuRUvxekkQdf42qVL+feLl9yvw+KahZt5LXbuPn/CJ8zamtfqrPI4/xtspst8e8f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Date" = _t, #"Amount in doc. curr." = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Date", type text}, {"Amount in doc. curr.", type number}}),
        #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Document Date", type date}}, "en-GB"),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type with Locale", "Index", 1, 1, Int64.Type),
        #"Filtered Rows" = Table.SelectRows(#"Added Index", each [#"Amount in doc. curr."] > 1),
        #"Added Index1" = Table.AddIndexColumn(#"Filtered Rows", "Index.1", 1, 1, Int64.Type),
        #"Merged Queries" = Table.NestedJoin(#"Added Index", {"Index"}, #"Added Index1", {"Index.1"}, "Added Index1", JoinKind.LeftOuter),
        #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"Amount in doc. curr."}, {"Added Index1.Amount in doc. curr."}),
        #"Renamed Columns" = Table.RenameColumns(#"Expanded Added Index1",{{"Added Index1.Amount in doc. curr.", "Output1"}}),
        #"Filtered Rows1" = Table.SelectRows(#"Renamed Columns", each [#"Amount in doc. curr."] < 0),
        #"Added Index2" = Table.AddIndexColumn(#"Filtered Rows1", "Index.1", 1, 1, Int64.Type),
        #"Merged Queries1" = Table.NestedJoin(#"Renamed Columns", {"Index"}, #"Added Index2", {"Index.1"}, "Added Index2", JoinKind.LeftOuter),
        #"Expanded Added Index2" = Table.ExpandTableColumn(#"Merged Queries1", "Added Index2", {"Amount in doc. curr."}, {"Added Index2.Amount in doc. curr."}),
        #"Renamed Columns1" = Table.RenameColumns(#"Expanded Added Index2",{{"Added Index2.Amount in doc. curr.", "Ouput2"}}),
        BufferedValues = List.Buffer(#"Renamed Columns1"[Output1]),
        CumulativeTotal = Table.AddColumn(#"Renamed Columns1", "Output3", each -16197615.03 + List.Sum(List.FirstN(BufferedValues,[Index])),type number),
        #"Removed Columns" = Table.RemoveColumns(CumulativeTotal,{"Index"})
    in
        #"Removed Columns"

     

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