Forum Discussion

ghostonpower225's avatar
ghostonpower225
Frequent Visitor
4 years ago

Delete Row after condition is met

I am trying to delete status "P" row once there is a date in due date actual for status "I". I can not seem to wrap my head around this one. Any support or help is much needed.

 

StatusIDComplete_1Actual_1Due_Date_CWVDue_Date_Original
ELAC4977097/13/2022 0:00 7/26/2022 0:007/26/2022 0:00
ELAC4977107/13/2022 0:00 7/26/2022 0:007/26/2022 0:00
IARC1877755/12/2022 0:005/11/2022 0:005/17/2022 0:005/17/2022 0:00
PKYC1991354/14/2022 0:005/9/2022 0:004/21/2022 0:004/21/2022 0:00
PKYC1991364/14/2022 0:00 4/21/2022 0:004/21/2022 0:00
EKCC2176194/27/2022 0:00 4/29/2022 0:004/29/2022 0:00
PKCC2176224/27/2022 0:00 4/29/2022 0:004/29/2022 0:00
IOKC2545403/14/2022 0:004/18/2022 0:003/18/2022 0:003/18/2022 0:00
POKC2545393/14/2022 0:00 3/18/2022 0:003/18/2022 0:00
IKKCC2175344/26/2022 0:00 4/29/2022 0:004/29/2022 0:00
IKKCC2175354/26/2022 0:00 4/29/2022 0:004/29/2022 0:00
PKCC2175404/26/2022 0:00 4/29/2022 0:004/29/2022 0:00
PKCC2175414/26/2022 0:00 4/29/2022 0:004/29/2022 0:00
PKCC2175424/19/2022 0:00 4/21/2022 0:004/21/2022 0:00
PKCC2175434/19/2022 0:00 4/21/2022 0:004/21/2022 0:00
ESLC3231144/20/2022 0:00 4/22/2022 0:004/22/2022 0:00
ESLC3231154/20/2022 0:00 4/22/2022 0:004/22/2022 0:00
PLAC4944163/16/2022 0:003/25/2022 0:003/21/2022 0:003/21/2022 0:00
PLAC4944173/16/2022 0:00 3/21/2022 0:003/21/2022 0:00
ESAC3813517/27/2022 0:00 8/2/2022 0:008/2/2022 0:00
ESAC3813537/27/2022 0:00 8/2/2022 0:008/2/2022 0:00
EARC1870203/11/2022 0:00 3/16/2022 0:003/16/2022 0:00
EARC1870213/11/2022 0:00 3/16/2022 0:003/16/2022 0:00
IKARC1865192/1/2022 0:00 2/4/2022 0:002/4/2022 0:00
IKARC1865202/1/2022 0:00 2/4/2022 0:002/4/2022 0:00
IKARC1869163/10/2022 0:00 3/16/2022 0:003/16/2022 0:00
IKARC1869173/10/2022 0:00 3/16/2022 0:003/16/2022 0:00

7 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    I have had another look at this.  Next time please post some sample data as text.  Presumably this is on a per ID basis

    --

    First, if you add a column (call it DTAndI ) to show if the Status is I and the date is not null (make it a 1 for this condition and 0 otherwise) - that helps in the next step.

    --

    Then add a custom column:

    let AnID = [id] in  if [Status] = "P" then  Table.MatchesAnyRows(previousStep, each  [id] = AnID and [DTAndI] = 1) else null

     that should put TRUE, FALSE or null in the column and you can filter out rows you don't want from the column header.

    • ghostonpower225's avatar
      ghostonpower225
      Frequent Visitor

      When I try the information you provided, it has added more rows. I am not sure why. I think it will work if I figure out why more rows are being added. Also, I have added some sample data. Thank you for your support.

  • HotChilli's avatar
    HotChilli
    Community Champion

    In Power Query?

    It will be a Table.SelectRows statement and the way to get the correct syntax is to get powerbi to generate it for you by filtering from the column header e.g. the Remove Empty option and then editing it to retain rows that meet 2 conditions: status not equal to I and date not equal to null (you'll have to write the right syntax for that bit)

  • HotChilli's avatar
    HotChilli
    Community Champion

    post your advanced editor code here and i'll have a look

    • ghostonpower225's avatar
      ghostonpower225
      Frequent Visitor

      let
      Source = Blank,
      #"Removed Duplicates" = Table.Distinct(Source, {"041_circuit_layout_order_base_nbr"}),
      #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "DTAndI", each if [CLO_Status] = "I" and [Due_Date_Actual] <> null then 1 else 0),
      #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each let AnID = [Combined_CLLI] in if [CLO_Status] = "P" then Table.MatchesAnyRows(#"Added Custom",each [Combined_CLLI] = AnID and [DTAndI] = 1) else null)
      in
      #"Added Custom1"

  • HotChilli's avatar
    HotChilli
    Community Champion

    The first column (step #"Added Custom") has the wrong name, it needs to be called DTandI.  It's called "Custom" at the moment. 

    The next column has a field [Combined_CLLI]. I don't see it in the data provided but if that's the id field everything should work.

    Let me know.

    If you get it working, you can filter rows out from the "Custom.1" header