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.
Hi ,
I want to delete all rows when it finds the text 'Item' under the Column: Item.
So when I find the first record under the column:item called item I want to delete all of the rows after it.
Example:
Item
12345
36665
fgtttu
gthjk
item - I want to delete all records from the text 'Item'
hgghj
Solved! Go to Solution.
Hello @craig811
the simplest way to do that is to use Table.FirstN
Here a example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFVitWJVjI2MzODsNLSS0pKSsHM9JKMrGwwK7MkNRfMyEhPz8hSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}}),
DeleteAfterItem = Table.FirstN
(
#"Changed Type",
each Text.Lower([Item])<>"item"
)
in
DeleteAfterItem
before
after
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
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
Hello @craig811
the simplest way to do that is to use Table.FirstN
Here a example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFVitWJVjI2MzODsNLSS0pKSsHM9JKMrGwwK7MkNRfMyEhPz8hSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}}),
DeleteAfterItem = Table.FirstN
(
#"Changed Type",
each Text.Lower([Item])<>"item"
)
in
DeleteAfterItem
before
after
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
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 sure this can be optimized but here is one approach:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFVitWJVjI2MzODsNLSS0pKSsHM9JKMrGwwK7MkNRfMyEhPz8hSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t]),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Delete", each List.Accumulate({0..[Index]},0,(state,current)=> state + (if #"Added Index"{current}[Item]="item" then 1 else 0))),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Delete] < 1)
in
#"Filtered Rows"
BEWARE: Power Query is case sensitive. "Item" and "item" are not the same thing.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.