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
craig811
Helper III
Helper III

Delete all rows from text: Item

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

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

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

Jimmy801_0-1613460077707.png

after

Jimmy801_1-1613460086630.png

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

 

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

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

Jimmy801_0-1613460077707.png

after

Jimmy801_1-1613460086630.png

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

 

lbendlin
Super User
Super User

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.

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