Forum Discussion
sahgir123
2 years agoFrequent Visitor
Want to create flag for max date
I have table like - input table - want to create new custom column, if Date column contain max date then 1 else 0 using M-Code.
| Content | Files | Date |
| Binary | Jan23 | 01/01/2023 |
| Binary | Feb23 | 01/02/2023 |
| Binary | Feb24 | 02/02/2024 |
| Binary | Feb24 | 14/02/2024 |
i want output in new column contain
| Files | O/p |
| Jan23 | 0 |
| Feb23 | 0 |
| Feb24 | 1 |
Feb 24 1
Hi sahgir123
See if this works for you
let maxDate = List.Max( List.Distinct( ChType[Date])), Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMSyyqVNJR8krMMzIG0gaG+kBkZADkxOogybulJsHljXDIm4DkjaDyJtjlDU0Q8rEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Content = _t, Files = _t, Date = _t]), ChType = Table.TransformColumnTypes( Source, {{"Date", type date}}, "nl-NL"), AddIsMax = Table.AddColumn(ChType, "IsMax", each if [Date] = maxDate then 1 else 0) in AddIsMaxThis gets me the Dates column from the ChType step: ChType[Date]
It's used in the maxDate variable to retrieve the max value and is used to add the IsMax column
I hope this is helpful
1 Reply
- m_dekorteResident Rockstar
Hi sahgir123
See if this works for you
let maxDate = List.Max( List.Distinct( ChType[Date])), Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMSyyqVNJR8krMMzIG0gaG+kBkZADkxOogybulJsHljXDIm4DkjaDyJtjlDU0Q8rEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Content = _t, Files = _t, Date = _t]), ChType = Table.TransformColumnTypes( Source, {{"Date", type date}}, "nl-NL"), AddIsMax = Table.AddColumn(ChType, "IsMax", each if [Date] = maxDate then 1 else 0) in AddIsMaxThis gets me the Dates column from the ChType step: ChType[Date]
It's used in the maxDate variable to retrieve the max value and is used to add the IsMax column
I hope this is helpful