Forum Discussion
How to differentiate between different rows in different columns
- 1 year ago
Hi TH20020520 Could you try these please
Sort the Table:
In Power Query, sort by Employee ID, Position, and Start Date.Add Index Column:
Add an Index column to track row order.Add Custom Column:
if [Employee Id] = Table.PreviousRow("Employee Id") and [Position] = Table.PreviousRow("Position") and Duration.Days(Date.From([Start Date]) - Date.From(Table.PreviousRow("End Date"))) <= 90 then PreviousGroup else NewGroupGroup Rows:
Generate unique group indices for rows meeting the criteria.
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance
- 1 year ago
Hi TH20020520, be more pricise for next time please:
- once the datetime is in "d-m-yyyy" format and once in "m-d-yyyy"
- the date 30th of Feb doesn't exist
- you should provide sample data as a table (if you don't know how - read note below my post please)
I'm not sure what should be your output - you should provide expected output based on sample data, but I gues you want something like this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcq5DQAgEAPBXhwDwubtBV3/bUDEkZCNtLsWqJIQwMiorHao7C4iLNxLz3bwuTg8aX43eWF319ZhtgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"employee id" = _t, #"start date" = _t, #"end date" = _t, position = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"start date", type date}, {"end date", type date}, {"position", Int64.Type}}, "sk-SK"), L = List.Buffer(Table.ToRows(ChangedType)), Gen = List.Skip(List.Generate( ()=> [ x = -1, y = 0 ], each [x] < List.Count(L), each [ x = [x]+1, r = [r]+1, y = try (if {L{x}{0}, L{x}{3}} = {L{[x]}{0}, L{[x]}{3}} and Duration.Days(L{x}{1} - L{[x]}{2}) <= 90 then [y] else r) otherwise [y]+1 ], each [y])), Merged = Table.FromColumns(Table.ToColumns(ChangedType) & {Gen}, Value.Type(Table.FirstN(ChangedType, 0) & #table(type table[Index=Int64.Type], {}))) in Merged
Hi TH20020520, be more pricise for next time please:
- once the datetime is in "d-m-yyyy" format and once in "m-d-yyyy"
- the date 30th of Feb doesn't exist
- you should provide sample data as a table (if you don't know how - read note below my post please)
I'm not sure what should be your output - you should provide expected output based on sample data, but I gues you want something like this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dcq5DQAgEAPBXhwDwubtBV3/bUDEkZCNtLsWqJIQwMiorHao7C4iLNxLz3bwuTg8aX43eWF319ZhtgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"employee id" = _t, #"start date" = _t, #"end date" = _t, position = _t]),
ChangedType = Table.TransformColumnTypes(Source,{{"start date", type date}, {"end date", type date}, {"position", Int64.Type}}, "sk-SK"),
L = List.Buffer(Table.ToRows(ChangedType)),
Gen = List.Skip(List.Generate(
()=> [ x = -1, y = 0 ],
each [x] < List.Count(L),
each [ x = [x]+1, r = [r]+1, y = try (if {L{x}{0}, L{x}{3}} = {L{[x]}{0}, L{[x]}{3}} and Duration.Days(L{x}{1} - L{[x]}{2}) <= 90 then [y] else r) otherwise [y]+1 ],
each [y])),
Merged = Table.FromColumns(Table.ToColumns(ChangedType) & {Gen}, Value.Type(Table.FirstN(ChangedType, 0) & #table(type table[Index=Int64.Type], {})))
in
Merged