Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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
Solved! Go to Solution.
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
GroupLast
Thank you so much
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
GroupLast
Copy 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
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"
as you can see all the transformation i made are in the code i send, and there is no sorting
Hello @hugoscp
then let's try this code
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.Buffer(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
you put a Table.Buffer but unfortunately the result for the code 803 remain the same :(.
I cant understand why some results are corret and others dont.
No i did not sort nothing, do you want me to sort?
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
GroupLast
Thank you so much
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
thank you again for the reply.
In some case worked and others dont
one example that didnt work:
result:
SOCDPR TPRDPR ARTDPR LastRow DTPDPR LastRow PBCDPR LastRow PDADPR
1 | PD | 803 | 20180920 | 3,28 | 0 |
data from this article(ARTDPR)
SOCDPR TPRDPR ARTDPR DTPDPR PBCDPR PDADPR
1 | PD | 803 | 0 | 4,87 | 45 |
1 | PD | 803 | 20121127 | 4,87 | 45 |
1 | PD | 803 | 20130930 | 4,87 | 48 |
1 | PD | 803 | 20131128 | 4,87 | 48 |
1 | PD | 803 | 20140206 | 4,87 | 38 |
1 | PD | 803 | 20140217 | 4,87 | 38 |
1 | PD | 803 | 20150108 | 4,87 | 50 |
1 | PD | 803 | 20160327 | 4,87 | 45 |
1 | PD | 803 | 20160413 | 4,87 | 50 |
1 | PD | 803 | 20161111 | 4,87 | 45 |
1 | PD | 803 | 20161215 | 4,87 | 50 |
1 | PD | 803 | 20170120 | 4,87 | 39 |
1 | PD | 803 | 20180110 | 4,87 | 35 |
1 | PD | 803 | 20180405 | 5,6 | 35 |
1 | PD | 803 | 20180411 | 5,6 | 35 |
1 | PD | 803 | 20180920 | 3,28 | 0 |
1 | PD | 803 | 20181011 | 5,6 | 41,96 |
1 | PD | 803 | 20181016 | 5,6 | 35 |
should be:
SOCDPR TPRDPR ARTDPR LastRow DTPDPR LastRow PBCDPR LastRow PDADPR
1 | PD | 803 | 20181016 | 5,6 | 35 |
Hello @hugoscp
my code works just fine. I applied my logic to your new data example. And my output is the one expected
maybe you are sorting the table before?
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
i am not sorting. I dont know why some work and others dont
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
31 | |
31 | |
20 | |
15 | |
12 |
User | Count |
---|---|
21 | |
20 | |
16 | |
10 | |
9 |