Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Richard_Halsall
Helper IV
Helper IV

Find a value in Grouped Data and Delete Rows

Hi

 

I am needing help with the following scenario. I have grouped data by ID and date with tasks for that day, I am trying to delete all rows in the group IF there is a taskType called 'Rest Day' (this task should not be delete) else do not delete any rows

Grouped Data

Richard_Halsall_0-1737561175309.png

For this day you would delete both rows with the taskType Working Hours to leave a single row with taskType 'Rest Day'

Richard_Halsall_1-1737561246206.png

For this day you would delete no rows

Richard_Halsall_2-1737561312216.png

For this day you would delete no rows

Richard_Halsall_3-1737561348392.png


taskType can contain values Working Hours, Rest Day, Standby Onsite & Standby Offsite

Any advice is much appreciated. Thanks

1 ACCEPTED SOLUTION
dufoq3
Community Champion
Community Champion

Hi @Richard_Halsall, for future requests provide sample data in usable format (not as a screenshot!)

 

Before

dufoq3_0-1737564537352.png

 

After

dufoq3_1-1737564558411.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjbQNzTSNzIwMlHSUQpKLS5RcEmsBDITgdhQKVYHTUV4flF2Zl66gkd+aVExVJkBKcoMzPUNDEHKTKmizBRJGabrYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Site_Start_Date = _t, taskType = _t, Contractor = _t, RestDayFlag = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Site_Start_Date", type date}, {"RestDayFlag", Int64.Type}}),
    GroupedRows = Table.Group(ChangedType, {"Site_Start_Date"}, {{"All", each _, type table}, {"T", each if List.Contains([RestDayFlag], 1) then Table.SelectRows(_, each [RestDayFlag] = 1) else _, type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Community Champion
Community Champion

Hi @Richard_Halsall, for future requests provide sample data in usable format (not as a screenshot!)

 

Before

dufoq3_0-1737564537352.png

 

After

dufoq3_1-1737564558411.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjbQNzTSNzIwMlHSUQpKLS5RcEmsBDITgdhQKVYHTUV4flF2Zl66gkd+aVExVJkBKcoMzPUNDEHKTKmizBRJGabrYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Site_Start_Date = _t, taskType = _t, Contractor = _t, RestDayFlag = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Site_Start_Date", type date}, {"RestDayFlag", Int64.Type}}),
    GroupedRows = Table.Group(ChangedType, {"Site_Start_Date"}, {{"All", each _, type table}, {"T", each if List.Contains([RestDayFlag], 1) then Table.SelectRows(_, each [RestDayFlag] = 1) else _, type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

BeaBF
Super User
Super User

@Richard_Halsall Hi! Can you paste your M code of the advanced editor?

 

BBF

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors