I’m practically new in Power Query, I did some simple queries in the past, but I’m trying to make a dinamyc one to proccess the data in a table to calculate the percentage distribution of the absolutes and this is what I have so far…
Basically I’m stuck in getting the final step (and the most important one), the division of the recorded value times the total of the column,
let
Source = Excel.CurrentWorkbook(){[Name="Line1_Abs"]}[Content],
//Organization will always be of type text. The others will be should be numbers, unless user error
#"Changed Type" = Table.TransformColumnTypes(Source, {{"Product_Regimen", type text}}),
//function to replace all values in all columns with percentages values
MultiplyReplace = (DataTable as table, DataTableColumns as list) =>
let
Counter = Table.ColumnCount(DataTable),
ReplaceCol = (DataTableTemp, i) =>
let
colName = DataTableColumns{i},
colTotal = List.Sum(Record.FieldValues(_, colName)),
//Line not doing the trick
ReplaceTable = Table.ReplaceValue(DataTableTemp,each Record.Field(_, colName), each if Record.Field(_, colName) is number then Record.Field(_, colName)/List.Sum(Record.FieldValues(_, colName)) else Record.Field(_, colName),Replacer.ReplaceValue,{colName})
in
if i = Counter-1 then ReplaceTable else @ReplaceCol(ReplaceTable, i+1)
in
ReplaceCol(DataTable, 0),
allColumns = Table.ColumnNames(#"Changed Type"),
#"Multiplied Numerics" = MultiplyReplace(#"Changed Type", allColumns)
in
#"Multiplied Numerics"
Ricardo De Angelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1