Forum Discussion
M001
2 years agoHelper I
Turn column names in M Language defined by variables
Hi there, I would like to check the data in my latest month column against previous month, and return Y for rows with data in the last two columns not equal The tricky part is the number of ...
m_dekorte
2 years agoResident Rockstar
Hi M001,
Copy this M code into a new blank query, replacing its content with:
(t as table) as table =>
let
cols = Table.ColumnNames( t ),
dates = List.Transform( cols, each
try Date.FromText(_, [Culture="en-GB"]) otherwise null
),
names = Table.MaxN(
Table.FromColumns(
{ cols, dates },
type table[ Fieldname=text, Value= any]
), "Value", 2
)[Fieldname],
addCol = Table.AddColumn( t, "Recent update", each
if Record.Field(_, names{0}) = Record.Field(_, names{1})
then "N"
else "Y", type text
)
in
addCol
Rename this new query to: fxRecentUpdate
Now you can invoke it on your table by selecting it from the drop down.
Note. This does require at least two "date field" column names to be present else it will return an error.
I hope this is helpful