Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hugoscp
Frequent Visitor

Max date by article

hello i have this data:

 

SOCDPR TPRDPR  ARTDPR  DTPDPR  PBCDPR  PDADPR

1PD28703,5228
1PD287201002282,530
1PD287201008263,5220
1PD287201009293,5228
1PD287201101193,5228
1PD28804,84128
1PD288201002283,490
1PD288201008264,8420
1PD288201009294,8428
1PD288201101194,8428
1PD288201112084,8435,2
1PD288201207053,2839,41
1PD288201210193,498,33
1PD288201309113,4950
1PD288201309303,6450
1PD288201404043,4929,41
1PD288201407313,4921,43
1PD288201409163,4928,57
1PD288201411263,4933,33

 

The result should be:

 

SOCDPR   TPRDPR  ARTDPR    DTPDPR   PBCDPR   PDADPR

1        PD      287        201101193,52      28
1        PD      288        201411263,49      33,33

 

How can i do that, please help me

 

Thank you          

2 ACCEPTED SOLUTIONS
Jimmy801
Community Champion
Community Champion

Did you try to sort the column of the Date Prior the Group-function?

View solution in original post

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

View solution in original post

12 REPLIES 12
Jimmy801
Community Champion
Community 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
	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

Jimmy801
Community Champion
Community Champion

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.

Jimmy801
Community Champion
Community Champion

Did you try to sort the column of the Date Prior the Group-function?

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

Jimmy801
Community Champion
Community 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

 

 

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

1PD80304,8745
1PD803201211274,8745
1PD803201309304,8748
1PD803201311284,8748
1PD803201402064,8738
1PD803201402174,8738
1PD803201501084,8750
1PD803201603274,8745
1PD803201604134,8750
1PD803201611114,8745
1PD803201612154,8750
1PD803201701204,8739
1PD803201801104,8735
1PD803201804055,635
1PD803201804115,635
1PD803201809203,280
1PD803201810115,641,96
1PD803201810165,635

 

should be:

 

SOCDPR  TPRDPR  ARTDPR   LastRow DTPDPR  LastRow PBCDPR  LastRow PDADPR

1    PD         803       20181016            5,6                      35
Jimmy801
Community Champion
Community Champion

Hello @hugoscp 

 

my code works just fine. I applied my logic to your new data example. And my output is the one expected

image.png

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors