Hi Community,
I’m exploring the possibilities of replacing values in bulk via the process that @Melissa explains in her course of Applied Problem Solving with Power Query/M, so far I managed to get it to work on entire cell contents, but not on cells in which the code only has to replace part of the contents.
To be concrete: I’d like to bulk replace values in table columns where some rows are in a YYYYQQ notation, and others are in the YYYYMM format. I only want to replace the Q1, Q2, Q3, Q4 with each related last month, so that the entire column can be converted into a date format.
Is there a way to change the M code for bulk replace values without having to specify exact cell contents?
Here’s the current M code that I used in the .xlsx attached:
let
ReplRec = [Q1 = "03", Q2 = "06", Q3 = "09", Q4 = "12", 1Q = "-03", 2Q = "-06", 3Q = "-09", 4Q = "-12"],
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Duplicated Column" = Table.DuplicateColumn(Source, "Report Date", "Report Month"),
BulkReplaceValues = Table.ReplaceValue(#"Duplicated Column", each {[Report Month],[Report Date]}, each Record.FieldOrDefault(ReplRec, {[Report Month],[Report Date]}),Replacer.ReplaceValue,{"Report Month", "Report Date"})
in
BulkReplaceValues
Dummy data.xlsx (15.3 KB)