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
gpiero
Skilled Sharer
Skilled Sharer

Removing Rows - http://community.powerbi.com/t5/Desktop/Removing-rows-in-Power-Bi/m-p/48104#M19015

I am trying to removing rows using parameters as indicated in the post above.

I have created the parameter but I did not understand how to delete the rows that match with parameter.

 

I can filter according to parameter but I can't delete.

 

Could you help me please?

Thanks

 

If I can...
1 ACCEPTED SOLUTION

It filters them in the query so that those rows are never imported into the data model so they are essentially "deleted" as part of the data load. This will not remove them from the source file but the data model will not have those rows in it. This is just a step in the query, you would have to return the rows from that line of the query. A full example query would be:

 

let
    Source = Csv.Document(File.Contents("C:\temp\powerbi\departments.csv"),[Delimiter=",", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Department", Int64.Type}, {"Name", type text}, {"DeptType", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Name] <> "Dept3"))
in
    #"Filtered Rows"

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
Greg_Deckler
Super User
Super User

I may not be understanding correctly, but you would need to use the parameter to filter in the query so that the data never makes it into the model. Are you trying to import everything and then delete it from the model? Or are you trying to delete it from the source?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

 

You are right since you do not know the background.

 

I am importing big data from ERP. The transaction that generates repeat on each page the column header.

Then shaping data, I need to remove all rows that contain the string that correspond to the column header.

 

 

Cattura.JPG

If I can...

Is there just one source and one format for the data being imported? You could essentially just set a filter on one of the columns to filter out all "Codice materiale" values in the "Codice materiale" column.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

Do you mean in this way?

 

 

#"Filtered Rows" = Table.SelectRows(#"Removed Columns", each Text.Contains([#" Materiale "], "Materiale"))

 

It aggregates all rows togheter and then I can remove duplicate and remove tha last row that is not duplicated.

Cattura1.JPG

 

Cattura2.JPG

 

How to deactivate the filter at the end?

 

#"Filtered Rows" = Table.SelectRows(#"Removed Columns", each Text.Contains([#" Materiale "], "Materiale"))

 

If I can...

I guess I was thinking like this:

 

    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([ Materiale] <> "Materiale"))


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

 

I think I misuderstood your suggestion.

 

How this code will allow to delete all rows that match the condition?

If I can...

It filters them in the query so that those rows are never imported into the data model so they are essentially "deleted" as part of the data load. This will not remove them from the source file but the data model will not have those rows in it. This is just a step in the query, you would have to return the rows from that line of the query. A full example query would be:

 

let
    Source = Csv.Document(File.Contents("C:\temp\powerbi\departments.csv"),[Delimiter=",", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Department", Int64.Type}, {"Name", type text}, {"DeptType", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Name] <> "Dept3"))
in
    #"Filtered Rows"

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

 

Thank you very much.

 

Now it works.

At first tentative I selected the field but i did not realize that in the formula PBI wrote

 

Table.SelectRows(#"Removed Blank Rows1", each ([#" Materiale "] = " Materiale ")),

instead of

 

Table.SelectRows(#"Removed Blank Rows1", each ([#" Materiale "] <> " Materiale ")),

 

let
    Source = Csv.Document(File.Contents("D:\OneDrive - x\Lavori\01.20_-_POWER BI DATASOURCE\WH Internal Activities\ZMB51_0_10000.TXT"),[Delimiter="|", Columns=20, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Change Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", type text}, {"Column13", type text}, {"Column14", type text}, {"Column15", type text}, {"Column16", type text}, {"Column17", type text}, {"Column18", type text}, {"Column19", type text}, {"Column20", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Change Type",{"Column1"}),
    #"Removed Blank Rows" = Table.SelectRows(#"Removed Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Blank Rows"),
    #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers","--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------","",Replacer.ReplaceText,{" Materiale "}),
    #"Removed Blank Rows1" = Table.SelectRows(#"Replaced Value", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Filtered Rows" = Table.SelectRows(#"Removed Blank Rows1", each ([#" Materiale "] <> " Materiale ")),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{""})
in
    #"Removed Columns1"

Thanks again for your precious help

 

If I can...

No problem, glad you got it working!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.