Last active
June 6, 2020 07:57
-
-
Save SchreiberLars/dd00edc7b7c9a679d0a8342ee6d5a59c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
/* | |
Creating a list of monthnames... | |
format and language of the list can easily by changes by the last two parameters | |
*/ | |
MonthsList = List.Transform( | |
{0..11}, | |
each Date.ToText(#date(1900, 1, 1) + Duration.From(_ * 31), "MMMM", "en-Us") | |
), | |
Source = Excel.CurrentWorkbook(){[Name = "Datenbasis"]}[Content], | |
//Get all column names | |
ColNames = List.Buffer(Table.ColumnNames(Source)), | |
//Get all Month columns | |
Headers = List.Buffer(List.Intersect({ColNames, MonthsList})), | |
//Create a row header 'Total' | |
FirstCol = Table.FromColumns({{"Total"}}, {ColNames{0}}), | |
/* | |
Use List.Accumulate to take the first column 'Cost centre' and | |
add all the month columns with the sum over the month column to it | |
*/ | |
AccTbl = List.Accumulate( | |
Headers, | |
FirstCol, | |
(st, cur) => | |
Table.AddColumn(st, cur, each List.Sum(Table.Column(Source, cur)), type number) | |
), | |
//Combine the source table and the sum table (with one row) | |
CombineTbls = Table.Combine({Source, AccTbl}) | |
in | |
CombineTbls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment