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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
Super User
Super User

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
Super User
Super User

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors