Forum Discussion
GFire
1 year agoHelper I
Remove the date filter and show all columns
I've developed the following code and need it to remove the date filter at the end and display all the columns in the dataset. The code's function is to remove duplicate records [N_Invoice] while ke...
- 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.
mromain
1 year agoRegular Visitor
Hi GFire
Here a possible solution:
let
Source = Excel.CurrentWorkbook(){[Name="Tabla1"]}[Content],
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
ChangedType = Table.TransformColumnTypes(PromotedHeaders,{{"N_Invoice", type text}, {"Index", Int64.Type}, {"Fecha", type date}}),
GroupByInvoice = Table.Group(ChangedType, {"N_Invoice"}, {{"MaxIndex", each List.Max([Index]), type nullable number}}),
MergeData = Table.NestedJoin(GroupByInvoice, {"N_Invoice", "MaxIndex"}, ChangedType, {"N_Invoice", "Index"}, "Data", JoinKind.LeftOuter),
SelectColumnData = Table.SelectColumns(MergeData,{"Data"}),
ExpandColumnsData = Table.ExpandTableColumn(SelectColumnData, "Data", {"N_Invoice", "Index", "Fecha"}, {"N_Invoice", "Index", "Fecha"})
in
ExpandColumnsData- GFire1 year agoHelper I
Hi mromain,
The table contains records from 2022, and they don't appear in the output table. Note that in my code, I remove duplicates within a range (the last 12 months). Once they're removed, the table expands and should remove the date filter and display all the remaining records.