Forum Discussion
Remove the date filter and show all columns
- 1 year ago
Hi GFire
I have updated the .Pbix as per your requirement. Please take a movement to review it and let us know if you need any adjustments.let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "bdRNasQwDIbhu2Q9hUi2/i7QI3QzzP2v0Uj5aC3iRaH4xbH8kMn7fXz/fJ0+p8XxOs7rb4qZH5/XX3G+VinL1Ov/tcxrlXcl5Fodu6eF5uq22LUqmyJnzqYosRbKie0ufq6Fcy5Hocd9AuV5HwKCj8eFiJDmepLk+cRI0lIOQHBwXZNWAoTbmiw3ECS8SVhNCApvFFYTwiKaheUGAkZQSzU8NGLVEM9dDI1YNfTMVYZGrBrKOTxDI6Slel2gEdpSDs/QCGsph2NoxKqhI4dnaMSqobMmvDX8PFvKudmRqKWaMJC4pXqjT6SmMXOCQUhNY+YEg5GaxsxjxkBqGpLHjInUNCRXhyA1DakxFKlpaE4woEFNQ+uB0KCmoXVlaFDTsLotNKhp1Bs1oUFNw+oYaFDT8HoWNKhp+P2FQWoafm9AahpRu6BBTSNqFzS4aUQdAw1uGvV5mtDgVcPq5yDQ4KeGQIOfGoJfyvSHhoxtyg0CDV6h7g+byDblBtFdqi+b2DblBvFtqnvFf/r8Ag==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [N_Invoice = _t, Index = _t, Fecha = _t] ), #"Changed Type" = Table.TransformColumnTypes(Source, { {"N_Invoice", type text}, {"Index", Int64.Type}, {"Fecha", Int64.Type} }), #"Converted Fecha" = Table.TransformColumns(#"Changed Type", { {"Fecha", each Date.From(_), type date} }), Today = Date.From(DateTime.LocalNow()), Last12Months = Date.AddMonths(Today, -12), RecentRows = Table.SelectRows(#"Converted Fecha", each [Fecha] >= Last12Months), MaxIndexPerInvoice = Table.Group(RecentRows, {"N_Invoice"}, { {"MaxIndex", each List.Max([Index]), Int64.Type} }), JoinOnMaxIndex = Table.NestedJoin(#"Converted Fecha", {"N_Invoice", "Index"}, MaxIndexPerInvoice, {"N_Invoice", "MaxIndex"}, "Matched", JoinKind.LeftOuter), WithFlag = Table.AddColumn(JoinOnMaxIndex, "Keep", each if Table.RowCount([Matched]) > 0 then true else null), #"Removed Matched" = Table.RemoveColumns(WithFlag, {"Matched"}), FinalFiltered = Table.SelectRows(#"Removed Matched", each [Keep] = true or [Fecha] < Last12Months), #"Removed Keep Column" = Table.RemoveColumns(FinalFiltered, {"Keep"}), Sorted = Table.Sort(#"Removed Keep Column", {{"N_Invoice", Order.Ascending}}) in Sorted
Thank you for being part of Fabric Community Forum.
Regards,
Karpurapu D,
Microsoft Fabric Community Support Team.
It continues to give the same error. It doesn't delete the duplicate record with the lowest index, keeping the one with the highest index. The INPUT table has 60 records, and the OUTPUT table also has 60 records. Therefore, it doesn't delete any records.
Hi GFire
I have updated the .Pbix as per your requirement. Please take a movement to review it and let us know if you need any adjustments.
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"bdRNasQwDIbhu2Q9hUi2/i7QI3QzzP2v0Uj5aC3iRaH4xbH8kMn7fXz/fJ0+p8XxOs7rb4qZH5/XX3G+VinL1Ov/tcxrlXcl5Fodu6eF5uq22LUqmyJnzqYosRbKie0ufq6Fcy5Hocd9AuV5HwKCj8eFiJDmepLk+cRI0lIOQHBwXZNWAoTbmiw3ECS8SVhNCApvFFYTwiKaheUGAkZQSzU8NGLVEM9dDI1YNfTMVYZGrBrKOTxDI6Slel2gEdpSDs/QCGsph2NoxKqhI4dnaMSqobMmvDX8PFvKudmRqKWaMJC4pXqjT6SmMXOCQUhNY+YEg5GaxsxjxkBqGpLHjInUNCRXhyA1DakxFKlpaE4woEFNQ+uB0KCmoXVlaFDTsLotNKhp1Bs1oUFNw+oYaFDT8HoWNKhp+P2FQWoafm9AahpRu6BBTSNqFzS4aUQdAw1uGvV5mtDgVcPq5yDQ4KeGQIOfGoJfyvSHhoxtyg0CDV6h7g+byDblBtFdqi+b2DblBvFtqnvFf/r8Ag==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let _t = ((type nullable text) meta [Serialized.Text = true])
in type table [N_Invoice = _t, Index = _t, Fecha = _t]
),
#"Changed Type" = Table.TransformColumnTypes(Source, {
{"N_Invoice", type text},
{"Index", Int64.Type},
{"Fecha", Int64.Type}
}),
#"Converted Fecha" = Table.TransformColumns(#"Changed Type", {
{"Fecha", each Date.From(_), type date}
}),
Today = Date.From(DateTime.LocalNow()),
Last12Months = Date.AddMonths(Today, -12),
RecentRows = Table.SelectRows(#"Converted Fecha", each [Fecha] >= Last12Months),
MaxIndexPerInvoice = Table.Group(RecentRows, {"N_Invoice"}, {
{"MaxIndex", each List.Max([Index]), Int64.Type}
}),
JoinOnMaxIndex = Table.NestedJoin(#"Converted Fecha", {"N_Invoice", "Index"}, MaxIndexPerInvoice, {"N_Invoice", "MaxIndex"}, "Matched", JoinKind.LeftOuter),
WithFlag = Table.AddColumn(JoinOnMaxIndex, "Keep", each if Table.RowCount([Matched]) > 0 then true else null),
#"Removed Matched" = Table.RemoveColumns(WithFlag, {"Matched"}),
FinalFiltered = Table.SelectRows(#"Removed Matched", each [Keep] = true or [Fecha] < Last12Months),
#"Removed Keep Column" = Table.RemoveColumns(FinalFiltered, {"Keep"}),
Sorted = Table.Sort(#"Removed Keep Column", {{"N_Invoice", Order.Ascending}})
in
Sorted
Thank you for being part of Fabric Community Forum.
Regards,
Karpurapu D,
Microsoft Fabric Community Support Team.