Forum Discussion
casar
1 year agoRegular Visitor
Generating rows based on values in several columns - Ungrouping values in a time series dataset
Hi everybody: I am looking for an automatic transformation of the following excel table containing FTE (Full-time employee) by Position. Area Position Code Company Jan-26 Feb-26 Mar-26 ...
- 1 year ago
I have responded at the site you cross posted at:
- 1 year ago
Hello everyone,
casar:
Another solution belowlet Source = #table({"Area", "Position", "Code", "Company", "Jan-26", "Feb-26", "Mar-26", "Apr-26", "May-26", "Jun-26", "Jul-26", "Aug-26", "Sep-26", "Oct-26", "Nov-26", "Dec-26"}, { {"SC", "Purchasing Officer", "SCO", "ABC", null, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {"Support", "Process Improvement Specialist", "SME", "ABC", null, null, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3}, {"Engineering", "Engineer", "ENG", "XYZ", null, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 2, 2, 2}, {"PM", "Project Manager", "PMM", "XYZ", 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3}, {"test", "test", "test", "test", null, 1, 1, 1, 1, null, 2, 2.15, 2, 3, 3, 3.4} }), DispatchFte = let ListDateColumns = List.Buffer(List.Select(Table.ColumnNames(Source), each not (try Date.FromText(_, "en-US"))[HasError])), fnChangeRecors = (r as record) as record => let listValues = Record.ToList(Record.SelectFields(r, ListDateColumns)), tableValues = let fnConvertValue = (v) => List.Transform({0 .. Number.RoundUp(List.Max(listValues))-1}, each if v = null then null else let fte = List.Max({List.Min({1, v-_}), 0}) in if fte = 0 then null else fte) in Table.FromColumns(List.Transform(listValues, fnConvertValue), ListDateColumns) in Record.AddField(Record.RemoveFields(r, ListDateColumns), "data", tableValues), ConvertFte = Table.FromRecords(Table.TransformRows(Source, fnChangeRecors)) in Table.ExpandTableColumn(ConvertFte, "data", ListDateColumns, ListDateColumns) in DispatchFte
p45cal
1 year agoSolution Supplier
I have responded at the site you cross posted at:
AlienSx
1 year agoSuper User
p45cal, I've responded over here as well
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
to_list = List.TransformMany(
Table.ToList(Source, (x) => x),
(x) => List.Zip(
List.Transform(
List.Skip(x, 4),
(w) => List.Repeat(
{if w is null then null else List.Min({w, 1})},
List.Max({w, 1})
)
)
),
(x, y) => List.FirstN(x, 4) & y
),
result = Table.FromList(to_list, (x) => x, Value.Type(Source))
in
result