Forum Discussion
Removing rows query
- 7 years ago
tgjones43, probably yes. in this case u get column1 with 1 only
.
new column calculate count rows by column1.
new column = countrows(filter(tableName;earlier([column1])=[column1]))
u can use report level filter [new column] = 4 then u get
other way u can filter your table in query editor
let
//your table Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWBsJzgLOeYPDjbBcwygqs0gqs0Aqssgqo1hqs1gas1gas1QVFrAlEbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
//group by column1
#"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Cnt", each Table.RowCount(_), type number}, {"list", each [Column2], type text}}), //filter column2 by cnt=4
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Cnt] = 4)),
//get our table #"Expanded {0}" = Table.ExpandListColumn(#"Filtered Rows", "list") in #"Expanded {0}" - 7 years ago
tgjones43,fix query
now u can get all columns from source table with filter by column2 with "D"
notice, in this way u should write columnNames by arm on step with bold font
i'm not sure, but mb exist the better way to write this query with better performance
let
//your table
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIE4hQgVorVgQg4gThIfOeYPKiSFLiYC5IaI6ghcAVGaIYYgQ0pghsDFjRGM8UE3RQTNFNMkExBFoMbEgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
//group by column1
#"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Max", each List.Max([Column2]), type number},{"records", each [[Column1],[Column2],[Column3],[Column4]], type text}}),
//filter column2 by max="D"
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Max] = "D")),
//delete usless columns
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"records"}),
//get filtered records
#"Expand{0}" = Table.ExpandTableColumn(#"Removed Other Columns","records",{"Column1","Column2","Column3","Column4"})
in
#"Expand{0}"
Thanks petrovnikitamai please could you write this in M language? I want to run this in the Power Query Editor.
tgjones43,fix query
now u can get all columns from source table with filter by column2 with "D"
notice, in this way u should write columnNames by arm on step with bold font
i'm not sure, but mb exist the better way to write this query with better performance
let
//your table
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIE4hQgVorVgQg4gThIfOeYPKiSFLiYC5IaI6ghcAVGaIYYgQ0pghsDFjRGM8UE3RQTNFNMkExBFoMbEgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
//group by column1
#"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Max", each List.Max([Column2]), type number},{"records", each [[Column1],[Column2],[Column3],[Column4]], type text}}),
//filter column2 by max="D"
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Max] = "D")),
//delete usless columns
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"records"}),
//get filtered records
#"Expand{0}" = Table.ExpandTableColumn(#"Removed Other Columns","records",{"Column1","Column2","Column3","Column4"})
in
#"Expand{0}"
- tgjones437 years agoHelper IV
Thank you petrovnikitamai you have been a great help.