Forum Discussion
Max date by article
hello i have this data:
SOCDPR TPRDPR ARTDPR DTPDPR PBCDPR PDADPR
| 1 | PD | 287 | 0 | 3,52 | 28 |
| 1 | PD | 287 | 20100228 | 2,53 | 0 |
| 1 | PD | 287 | 20100826 | 3,52 | 20 |
| 1 | PD | 287 | 20100929 | 3,52 | 28 |
| 1 | PD | 287 | 20110119 | 3,52 | 28 |
| 1 | PD | 288 | 0 | 4,841 | 28 |
| 1 | PD | 288 | 20100228 | 3,49 | 0 |
| 1 | PD | 288 | 20100826 | 4,84 | 20 |
| 1 | PD | 288 | 20100929 | 4,84 | 28 |
| 1 | PD | 288 | 20110119 | 4,84 | 28 |
| 1 | PD | 288 | 20111208 | 4,84 | 35,2 |
| 1 | PD | 288 | 20120705 | 3,28 | 39,41 |
| 1 | PD | 288 | 20121019 | 3,49 | 8,33 |
| 1 | PD | 288 | 20130911 | 3,49 | 50 |
| 1 | PD | 288 | 20130930 | 3,64 | 50 |
| 1 | PD | 288 | 20140404 | 3,49 | 29,41 |
| 1 | PD | 288 | 20140731 | 3,49 | 21,43 |
| 1 | PD | 288 | 20140916 | 3,49 | 28,57 |
| 1 | PD | 288 | 20141126 | 3,49 | 33,33 |
The result should be:
SOCDPR TPRDPR ARTDPR DTPDPR PBCDPR PDADPR
| 1 | PD | 287 | 20110119 | 3,52 | 28 |
| 1 | PD | 288 | 20141126 | 3,49 | 33,33 |
How can i do that, please help me
Thank you
- Did you try to sort the column of the Date Prior the Group-function?
it work like this
let
Origem = Odbc.DataSource("dsn=inout.swapfilio", [HierarchicalNavigation=true]),
B606D19C_Database = Origem{[Name="B606D19C",Kind="Database"]}[Data],
SWAPFILIO_Schema = B606D19C_Database{[Name="SWAPFILIO",Kind="Schema"]}[Data],
GEFPR_Table = SWAPFILIO_Schema{[Name="GEFPR",Kind="Table"]}[Data],
#"Linhas Filtradas" = Table.SelectRows(GEFPR_Table, each [SOCDPR] = 1),
#"Linhas Filtradas1" = Table.SelectRows(#"Linhas Filtradas", each [TPRDPR] = "PD"),
#"Colunas Removidas" = Table.RemoveColumns(#"Linhas Filtradas1",{"MOEDPR", "CLIDPR", "PTEDPR", "MODDPR", "EMBDPR", "GFMDPR", "QESDPR", "DSFDPR", "DSVDPR", "QBBDPR", "BNSDPR", "IVADPR", "DTFDPR", "RGADPR", "TPDDPR", "DUADPR", "MTPDPR", "ZZ6"}),
#"Linhas Ordenadas" = Table.Buffer(Table.Sort(#"Colunas Removidas",{{"DTPDPR", Order.Ascending}})),
GroupLast = Table.Group
(
#"Linhas Ordenadas",
{"SOCDPR", "TPRDPR", "ARTDPR"},
{
{"LastRow DTPDPR", each List.Last([DTPDPR])},
{"LastRow PBCDPR", each List.Last([PBCDPR])},
{"LastRow PDADPR", each List.Last([PDADPR])}})
in
GroupLastThank you so much
12 Replies
- Jimmy801Community Champion
Hello hugoscp
you didn't specify how the result is obtained. By checking it I found a logic, but don't know if this is the real logic.
However i grouped it by the first 3 columns and then calculated the last element of each group. Is this logic working?
Here the complete code example
let Source = #table ( {"SOCDPR","TPRDPR","ARTDPR","DTPDPR","PBCDPR","PDADPR"}, { {"1","PD","287","0","3,52","28"}, {"1","PD","287","20100228","2,53","0"}, {"1","PD","287","20100826","3,52","20"}, {"1","PD","287","20100929","3,52","28"}, {"1","PD","287","20110119","3,52","28"}, {"1","PD","288","0","4,841","28"}, {"1","PD","288","20100228","3,49","0"}, {"1","PD","288","20100826","4,84","20"}, {"1","PD","288","20100929","4,84","28"}, {"1","PD","288","20110119","4,84","28"}, {"1","PD","288","20111208","4,84","35,2"}, {"1","PD","288","20120705","3,28","39,41"}, {"1","PD","288","20121019","3,49","8,33"}, {"1","PD","288","20130911","3,49","50"}, {"1","PD","288","20130930","3,64","50"}, {"1","PD","288","20140404","3,49","29,41"}, {"1","PD","288","20140731","3,49","21,43"}, {"1","PD","288","20140916","3,49","28,57"}, {"1","PD","288","20141126","3,49","33,33"} } ), GroupLast = Table.Group ( Source, {"SOCDPR", "TPRDPR", "ARTDPR"}, { {"LastRow DTPDPR", each List.Last([DTPDPR])}, {"LastRow PBCDPR", each List.Last([PBCDPR])}, {"LastRow PDADPR", each List.Last([PDADPR])}}) in GroupLastCopy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy- hugoscpFrequent Visitor
thank you for the answer. Thats it, but i had a filter in the article codes.
Now with all of the article codes, i want exactly the some as before. How do i do it?
thank you
let
Origem = Odbc.DataSource("dsn=inout.swapfilio", [HierarchicalNavigation=true]),
B606D19C_Database = Origem{[Name="B606D19C",Kind="Database"]}[Data],
SWAPFILIO_Schema = B606D19C_Database{[Name="SWAPFILIO",Kind="Schema"]}[Data],
GEFPR_Table = SWAPFILIO_Schema{[Name="GEFPR",Kind="Table"]}[Data],
#"Linhas Filtradas" = Table.SelectRows(GEFPR_Table, each [SOCDPR] = 1),
#"Linhas Filtradas1" = Table.SelectRows(#"Linhas Filtradas", each [TPRDPR] = "PD"),
#"Colunas Removidas" = Table.RemoveColumns(#"Linhas Filtradas1",{"MOEDPR", "CLIDPR", "PTEDPR", "MODDPR", "EMBDPR", "GFMDPR", "QESDPR", "DSFDPR", "DSVDPR", "QBBDPR", "BNSDPR", "IVADPR", "DTFDPR", "RGADPR", "TPDDPR", "DUADPR", "MTPDPR", "ZZ6"})
in
#"Colunas Removidas"- Jimmy801Community Champion
Hello hugoscp
this would the adapted code... hoping that data structure is the same
let Origem = Odbc.DataSource("dsn=inout.swapfilio", [HierarchicalNavigation=true]), B606D19C_Database = Origem{[Name="B606D19C",Kind="Database"]}[Data], SWAPFILIO_Schema = B606D19C_Database{[Name="SWAPFILIO",Kind="Schema"]}[Data], GEFPR_Table = SWAPFILIO_Schema{[Name="GEFPR",Kind="Table"]}[Data], #"Linhas Filtradas" = Table.SelectRows(GEFPR_Table, each [SOCDPR] = 1), #"Linhas Filtradas1" = Table.SelectRows(#"Linhas Filtradas", each [TPRDPR] = "PD"), #"Colunas Removidas" = Table.RemoveColumns(#"Linhas Filtradas1",{"MOEDPR", "CLIDPR", "PTEDPR", "MODDPR", "EMBDPR", "GFMDPR", "QESDPR", "DSFDPR", "DSVDPR", "QBBDPR", "BNSDPR", "IVADPR", "DTFDPR", "RGADPR", "TPDDPR", "DUADPR", "MTPDPR", "ZZ6"}), GroupLast = Table.Group ( #"Colunas Removidas", {"SOCDPR", "TPRDPR", "ARTDPR"}, { {"LastRow DTPDPR", each List.Last([DTPDPR])}, {"LastRow PBCDPR", each List.Last([PBCDPR])}, {"LastRow PDADPR", each List.Last([PDADPR])}}) in GroupLast
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy