Forum Discussion
FlorisMK
Helper I
3 years agoReplace specific value with column name in variable number of columns
Starting from a calendar ListObject in Excel which has rows for each date (first column = "Date"), columns for each employee, and a "V" in each cell where an employee is on vacation on that date. I ...
- 3 years ago
Yes, 2nd statement is the answer where Source will be replaced with #"Changed Type". So the code becomes below
let Source = Excel.CurrentWorkbook(){[Name="TablePlannedVacations"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Aparupa", type text}, {"Eunice", type text}, {"Floris", type text}, {"Frank", type text}, {"Gijsbert", type text}, {"Jasper", type text}, {"Ken", type text}, {"Mahesh", type text}, {"Mark", type text}, {"Niels", type text}, {"Remco", type text}, {"Rob", type text}, {"Sepideh", type text}, {"Stan", type text}, {"Thijs", type text}}), Custom1 = Table.FromRecords( Table.TransformRows(#"Changed Type", (r) => List.Accumulate(Table.ColumnNames(#"Changed Type"), r, (s,c)=> Record.TransformFields(s,{{c, each if _ = "V" then c else null}}))) , Value.Type(#"Changed Type")) in Custom1 - 3 years ago
Hi,
Unpivot, Replace Value, Pivot
let
Source = Your_Source,
Unpivot = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
Replace_Value = Table.ReplaceValue(Unpivot,"V",each [Attribute],Replacer.ReplaceText,{"Value"}),
Pivot = Table.Pivot(Replace_Value, List.Distinct(Replace_Value[Attribute]), "Attribute", "Value")
in
PivotStéphane
slorin
Super User
3 years agoBonjour
Je vais répondre en français car mon anglais n'est pas assez bon (vous demanderez à votre navigateur de traduire !)
Une bonne pratique consiste à transformer vos données qui ont les noms en colonne en les dépivotant (unpivot) afin d'avoir une colonne avec les dates et une colonne avec les noms.
Dans votre cas, il suffit ensuite de remplacer les V par les noms (la colonne Attribute contient les noms, la colonne Value uniquement la lettre V).
Enfin, comme vous souhaitez avoir les noms en colonne, il faut pivoter afin de retrouver la disposition initiale.
Stéphane
- FlorisMK3 years ago
Helper I
Parfait, merci!