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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
yogesh9ngp
New Member

Want to Delete and Retain Rows based on a Specific Value in the Column

Hello, I am working on a project and I am stuck on a problem. I want to delete Rows based on multiple conditions on more than one column. Following is the Example of the Data.

 

Customer_NumberDateAppointment_StatusVerdict
62984301/14/2019A 
62984901/16/2019A 
62984902/20/2019A 
62984903/13/2019A 
62984903/14/2019A 
62984908/29/2019A 
62984908/29/2019A 
62984909/17/2019A 
62984901/27/2020A 
62984902/12/2020A 
62984903/4/2020A 
94850341/30/2019A 
94850341/31/2019A 
94850344/29/2019A 
94850345/17/2019A 
948503411/19/2019A 
94850346/12/2020S 

 

I would like the Code to read through Each and Every line and use the following Logic.

1. For the First Customer_Number (6298490) :

       * I would want the code to check for each date if there is a Corresponding Value of "S" in the (Appointment_Status) colum . As            soon as it detects tje value "S" it should stop the detection for that particular Customer_Number and it should say as                        "Appointment Scheduled" in the column (Verdict) next to it. 

       * IF there is no Corresponding Value of "S" then it should "DELETE" all the earlier rows but keep the row with the most recent             date and say as " NO - Appointment Scheduled" in the column (Verdict) next to it.

       * Once it has gone through all the rows of the First Customer_Number it should repreat it for the next Customer_Number.

      

 

The Desirable Output I am looking for is :

 

Customer_NumberDateAppointment_StatusVerdict
62984301/14/2019AThis row should be Deleted
62984901/16/2019AThis row should be Deleted
62984902/20/2019AThis row should be Deleted
62984903/13/2019AThis row should be Deleted
62984903/14/2019AThis row should be Deleted
62984908/29/2019AThis row should be Deleted
62984908/29/2019AThis row should be Deleted
62984909/17/2019AThis row should be Deleted
62984901/27/2020AThis row should be Deleted
62984902/12/2020AThis row should be Deleted
62984903/4/2020ANO- Appointment Scheduled
94850341/30/2019AThis row should be Deleted
94850341/31/2019AThis row should be Deleted
94850344/29/2019AThis row should be Deleted
94850345/17/2019AThis row should be Deleted
948503411/19/2019AThis row should be Deleted
94850346/12/2020SAppointment Scheduled

 

So, Finally it would look like:

 

 

Customer_NumberDateAppointment_StatusVerdict
62984903/4/2020ANO- Appointment Scheduled
94850346/12/2020SAppointment Scheduled

 

Please Help.

 

Regards,

Yogesh

 

      

 

 

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @yogesh9ngp ,

 

We can create a calculated table as below.

Table 2 = 
VAR k =
    ADDCOLUMNS (
        'Table',
        "A",
        VAR a =
            ADDCOLUMNS (
                'Table',
                "days", ABS ( DATEDIFF ( TODAY (), 'Table'[Date], DAY ) )
            )
        VAR days_ =
            ABS ( DATEDIFF ( TODAY (), 'Table'[Date], DAY ) )
        VAR b =
            MINX (
                FILTER (
                    a,
                    'Table'[Appointment_Status] = EARLIER ( 'Table'[Appointment_Status] )
                ),
                [days]
            )
        VAR s =
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    'Table',
                    'Table'[Appointment_Status] = "S"
                        && 'Table'[Appointment_Status] = EARLIER ( 'Table'[Appointment_Status] )
                )
            )
        RETURN
            IF (
                days_ = b
                    && 'Table'[Appointment_Status] <> "S",
                "NO- Appointment Scheduled",
                IF ( 'Table'[Appointment_Status] = "S", "Appointment Scheduled" )
            )
    )
RETURN
    FILTER ( k, [A] <> BLANK () )

Capture.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.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @yogesh9ngp ,

 

We can create a calculated table as below.

Table 2 = 
VAR k =
    ADDCOLUMNS (
        'Table',
        "A",
        VAR a =
            ADDCOLUMNS (
                'Table',
                "days", ABS ( DATEDIFF ( TODAY (), 'Table'[Date], DAY ) )
            )
        VAR days_ =
            ABS ( DATEDIFF ( TODAY (), 'Table'[Date], DAY ) )
        VAR b =
            MINX (
                FILTER (
                    a,
                    'Table'[Appointment_Status] = EARLIER ( 'Table'[Appointment_Status] )
                ),
                [days]
            )
        VAR s =
            CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    'Table',
                    'Table'[Appointment_Status] = "S"
                        && 'Table'[Appointment_Status] = EARLIER ( 'Table'[Appointment_Status] )
                )
            )
        RETURN
            IF (
                days_ = b
                    && 'Table'[Appointment_Status] <> "S",
                "NO- Appointment Scheduled",
                IF ( 'Table'[Appointment_Status] = "S", "Appointment Scheduled" )
            )
    )
RETURN
    FILTER ( k, [A] <> BLANK () )

Capture.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.
Greg_Deckler
Community Champion
Community Champion

Create a custom column in Power Query that implements your logic and returns 1 if it does and 0 if it doesn't. Now, filter the table for just 0 values. Remove column.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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