Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi All,
I am trying to convert Transactionlines (TL) into periodic snapshot for a balance sheet model using PowerQuery.
The TL table is loaded in PQ and has Date, AccountCode and Amount:
Next step is to create a new Column RTTable with EndOfMonth Dates - and for each AccountCode i like a Running Total.
See picture for Accountcode 1600. Next to 1600 should be another Account Code column etc.
I am able to code this in DAX (see code below for eg AccountCode 1600) but howis this done in PowerQuery ?
Once realised i will unpivot the RTTable and it is then input for the balance sheet model.
Desired tabe:
DAX code:
1600 =var CurrentDate=RTTable[Date]
var CurrentLedger=1600
var FilteredTable = FILTER('TranactionLines','TransactionLines'[AltDate]<=CurrentDate && 'TransactionLines'[AccountKey]=CurrentLedger)
return
CALCULATE(SUM('TransactionLines'[Amount]),FilteredTable)
any help is appreciated
Solved! Go to Solution.
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
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
Hi @Swalker,
there are many examples on this platform already:
e.g. Solved: Re: Cumulative sum in Power query editor - Microsoft Power BI Community
or here using Google search on cumulative total: Running Total in Power Query (Ultimate Guide) - BI Gorilla
Cheers,
John
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |