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
Anonymous
Not applicable

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:ExampleExampleThanks!

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

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 others find it more quickly.
Anonymous
Not applicable

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
Community Champion
Community Champion

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!
Thank you for the kudos 🙂

Stachu
Community Champion
Community Champion

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!
Thank you for the kudos 🙂

Anonymous
Not applicable

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.

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