Forum Discussion
PowerQuery M Running Total Date and LedgerKey
- Anonymous3 years ago
Hi Swalker ,
Please refer to the following steps:
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "ddBRDoQwCATQu/TbHWFaWjyL8f7XsJqazZb1i4+XYQj7nnTVlaKWlmR2D6WALR3LD2oV6eOjxWA5qPFSGlgfkxAlSsBeyrv0a/NWLRAP2IO5j9ogOSZHpStUH+W8lyAj6rhWvGGL4dFrjj/ZUdsE5VWnxTm86c3H1e7wqFLKpb5t6Hic", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AltDate = _t, GLAccountCode = _t, AmountDC = _t] ), #"Changed Type" = Table.TransformColumnTypes( Source, {{"AltDate", type date}, {"GLAccountCode", Int64.Type}, {"AmountDC", type number}} ), #"Grouped Rows" = Table.Group( #"Changed Type", {"GLAccountCode"}, {{"Data", each Table.AddIndexColumn(_, "Index", 1, 1), type table}} ), Custom1 = Table.TransformColumns( #"Grouped Rows", { "Data", (x) => Table.AddColumn(x, "Running Total", each List.Sum(List.FirstN(x[AmountDC], [Index]))) } ), #"Expanded Data" = Table.ExpandTableColumn( Custom1, "Data", {"AltDate", "Running Total"}, {"AltDate", "Running Total"} ), #"Pivoted Column" = Table.Pivot( Table.TransformColumnTypes(#"Expanded Data", {{"GLAccountCode", type text}}, "en-US"), List.Distinct( Table.TransformColumnTypes(#"Expanded Data", {{"GLAccountCode", type text}}, "en-US")[ GLAccountCode ] ), "GLAccountCode", "Running Total", List.Sum ), #"Filled Down" = Table.FillDown( #"Pivoted Column", {"5515", "1600", "1520", "5512", "5513", "1100", "440"} ) in #"Filled Down"result:
Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi Swalker ,
Please refer to the following steps:
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"ddBRDoQwCATQu/TbHWFaWjyL8f7XsJqazZb1i4+XYQj7nnTVlaKWlmR2D6WALR3LD2oV6eOjxWA5qPFSGlgfkxAlSsBeyrv0a/NWLRAP2IO5j9ogOSZHpStUH+W8lyAj6rhWvGGL4dFrjj/ZUdsE5VWnxTm86c3H1e7wqFLKpb5t6Hic",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [AltDate = _t, GLAccountCode = _t, AmountDC = _t]
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"AltDate", type date}, {"GLAccountCode", Int64.Type}, {"AmountDC", type number}}
),
#"Grouped Rows" = Table.Group(
#"Changed Type",
{"GLAccountCode"},
{{"Data", each Table.AddIndexColumn(_, "Index", 1, 1), type table}}
),
Custom1 = Table.TransformColumns(
#"Grouped Rows",
{
"Data",
(x) => Table.AddColumn(x, "Running Total", each List.Sum(List.FirstN(x[AmountDC], [Index])))
}
),
#"Expanded Data" = Table.ExpandTableColumn(
Custom1,
"Data",
{"AltDate", "Running Total"},
{"AltDate", "Running Total"}
),
#"Pivoted Column" = Table.Pivot(
Table.TransformColumnTypes(#"Expanded Data", {{"GLAccountCode", type text}}, "en-US"),
List.Distinct(
Table.TransformColumnTypes(#"Expanded Data", {{"GLAccountCode", type text}}, "en-US")[
GLAccountCode
]
),
"GLAccountCode",
"Running Total",
List.Sum
),
#"Filled Down" = Table.FillDown(
#"Pivoted Column",
{"5515", "1600", "1520", "5512", "5513", "1100", "440"}
)
in
#"Filled Down"
result:
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum