cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
guimatheus92 Frequent Visitor
Frequent Visitor

Delete rows from dataset with rule if has more than one row

Hello everyone!

 

I'm new to PowerQuery/PowerBI, I've got a table that I'd like to remove some rows if a rule applies.

 

What I need:

If  column "VALID" has "YES" in the data, delete rows that contains "NO" (if they are the same information only).

I filtered the data to show the example below, in this case, I'd like to delete the first row that contains "NO" and keep only the row with "YES", because all the rest are the same.

If rows contains only the value "NO", so do nothing.

 

Example:EXAMPLE.jpgExampleThanks!

5 REPLIES 5
Stachu Super Contributor
Super Contributor

Re: Delete rows from dataset with rule if has more than one row

I'd suggest using GroupBy with Max of VALID, like this
Capture.PNG

List.Max can be used with strings following alphabetic order, so Yes will always come ahead of No

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Community Support Team
Community Support Team

Re: Delete rows from dataset with rule if has more than one row

Hi @guimatheus92 ,

 

We can use calculated table to work around instead of M code in power query.

CleanTable =
VAR T =
    ALL ( 'table' )
VAR Y =
    FILTER ( T, [VALID] = "YES" )
VAR YN =
    SELECTCOLUMNS (
        Y,
        "COD_EMPRS", [COD_EMPRS],
        "NUM_RGTRO_EMPRG", [NUM_RGTRO_EMPRG],
        "NUM_IDNTF_RPTANT", [NUM_IDNTF_RPTANT],
        "VALID", "NO",
        "EMP/MAT/REP", [EMP/MAT/REP]
    )
RETURN
    EXCEPT ( T, YN )

2.PNG

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
guimatheus92 Frequent Visitor
Frequent Visitor

Re: Delete rows from dataset with rule if has more than one row

I didn't try this solution yet, but I think it wont wok. Because I'm going to merge this table with another table, so it'll bring both results.

guimatheus92 Frequent Visitor
Frequent Visitor

Re: Delete rows from dataset with rule if has more than one row

I couldn't open your file, it said my version was newer than yours.

But I'm going to merge this table with another table, so I need only one result.

 

Rule:

If has "YES" and "NO", keep only "YES".

Otherwise, bring wherever has in the column.

Stachu Super Contributor
Super Contributor

Re: Delete rows from dataset with rule if has more than one row

if you have to do it in M then the Group By + List.Max I posted earlier will do the job

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 295 members 2,843 guests
Please welcome our newest community members: