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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
SoufTC
Helper I
Helper I

Delete rows based on calculated number

I’m having trouble to delete rows based on calcluted # number.

 

I have 3 tables.

 

1. A table that defines unique list of call (call)[List] per day (call)[Date]. each call has an answer status (call)[Status]. I created a column to have a unique field (call)[Key]

 

Call which appears as following :

|   List          |  Status  |    Date            |    Key
-------------------------------------------------------------
|   List1         |  A        |    2022-02-09  |   List1 2022-02-09
|   List1         |  A        |    2022-02-09  |   List1 2022-02-09
|   List1         |  DO     |    2022-02-09  |   List1 2022-02-09
|   List1         |  DO     |    2022-02-09  |   List1 2022-02-09
|   List1         |  DO      |    2022-02-09  |   List1 2022-02-09
|   List2         |  A        |    2022-02-09  |   List2 2022-02-09
|   List2         |  DO      |    2022-02-09  |   List2 2022-02-09
|   List2         |  DO      |    2022-02-09  |   List2 2022-02-09
|   List3         |  A        |    2022-02-09  |   List3 2022-02-09
|   List3         |  DO        |    2022-02-09  |   List3 2022-02-09
|   List3         |  DO      |    2022-02-09  |   List3 2022-02-09
|   List1         |  C        |    2022-02-10  |   List1 2022-02-10
|   List2         |  A        |    2022-02-10  |   List1 2022-02-10
|   List2         |  DO        |    2022-02-10  |   List1 2022-02-10
|   List2         |  A        |    2022-02-10  |   List1 2022-02-10
|   List3         |  DO        |    2022-02-10  |   List1 2022-02-10
|   List3         |  A        |    2022-02-10  |   List1 2022-02-10

 

2. A table a repository Status (Status )[Names] and (Status)[Status]; The join with the (Call)table is done with the (Status)[Status]

 

Status which appears as following :

 

|   Names       |  Status       |
-----------------------------
|   answer        |      A          |
|   drop out     |     DO         |
|   cancel         |     C            |

 

2. A table Number with a calculated column (Number)[#drop] ; The join with the (Call)table is done with the (Call)[Key]

 

Number which appears as following :

|   Key                       |  # drop    |   
-------------------------------------
| List1 2022-02-09    |  2       |
| List2 2022-02-09    |  2        |
| List3 2022-02-09    |  1        |
| List1 2022-02-10    |  0        |
| List2 2022-02-10    |  1        |
| List3 2022-02-10    |  1        |

 

I want to create a new table called NewDF by deleting the rows based on (Number)[#drop] and with (Status )[Names] = "drop out"

 

Desired result is the following:

 

|   List          |  Status  |    Date            |    Key
-------------------------------------------------------------
|   List1         |  A        |    2022-02-09  |   List1 2022-02-09
|   List1         |  A        |    2022-02-09  |   List1 2022-02-09
|   List1         |  DO     |    2022-02-09  |   List1 2022-02-09
|   List2         |  A        |    2022-02-09  |   List2 2022-02-09
|   List3         |  A        |    2022-02-09  |   List3 2022-02-09
|   List3         |  DO      |    2022-02-09  |   List3 2022-02-09
|   List1         |  C        |    2022-02-10  |   List1 2022-02-10
|   List2         |  A        |    2022-02-10  |   List1 2022-02-10
|   List2         |  A        |    2022-02-10  |   List1 2022-02-10
|   List3         |  A        |    2022-02-10  |   List1 2022-02-10

 

Please, any help?

Thank's in advance

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@SoufTC this was super super tricky.
Also, you had mistakes in your tables you copied (look at the first table you pasted), so make sure you test this with accurate data.
Attaching the file:
Delete Rows.pbix
It involved extra neccesary steps in Power Query so make sure you follow them and then I could have written this calculated table:

 

Calc Table = 
VAR _tbl1 = 
    SELECTCOLUMNS(
        FILTER(
            ADDCOLUMNS(
                FactCalls,
                "@Removal Index", 
                IF(
                    RELATED(DimStatus[Names]) <> "drop out", 
                    0,
                    RANKX(FILTER(FactCalls,FactCalls[Key] = EARLIER(FactCalls[Key])), FactCalls[Index], ,ASC) - COUNTROWS(FILTER(FactCalls, FactCalls[Status] <> "DO" && FactCalls[Key] = EARLIER(FactCalls[Key])))
                ) - RELATED(DimDrops[# drop])
            ),
            [@Removal Index] < 0
        ),
        "List", [List],
        "Status", [Status],
        "Date", [Date],
        "Key", [Key]
    )
RETURN
    _tbl1

 




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

3 REPLIES 3
SoufTC
Helper I
Helper I

@SpartaBIthank's for your response. from the table Number we define how many rows to delete according to the (Number)[#drop]: for example according to Table Number for the (Call)[Key] = List1 2022-02-09  we have (Number)[#drop] = 2 rows to delete. In (call)[List] we have 3 rows = DO so we keep delete 2 and keep 1. I don't know if clear enough thank's in advance

SpartaBI
Community Champion
Community Champion

@SoufTC this was super super tricky.
Also, you had mistakes in your tables you copied (look at the first table you pasted), so make sure you test this with accurate data.
Attaching the file:
Delete Rows.pbix
It involved extra neccesary steps in Power Query so make sure you follow them and then I could have written this calculated table:

 

Calc Table = 
VAR _tbl1 = 
    SELECTCOLUMNS(
        FILTER(
            ADDCOLUMNS(
                FactCalls,
                "@Removal Index", 
                IF(
                    RELATED(DimStatus[Names]) <> "drop out", 
                    0,
                    RANKX(FILTER(FactCalls,FactCalls[Key] = EARLIER(FactCalls[Key])), FactCalls[Index], ,ASC) - COUNTROWS(FILTER(FactCalls, FactCalls[Status] <> "DO" && FactCalls[Key] = EARLIER(FactCalls[Key])))
                ) - RELATED(DimDrops[# drop])
            ),
            [@Removal Index] < 0
        ),
        "List", [List],
        "Status", [Status],
        "Date", [Date],
        "Key", [Key]
    )
RETURN
    _tbl1

 




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

SpartaBI
Community Champion
Community Champion

@SoufTC I'm missing what logic do you want to get from the KEY / # Drop table.
I wrote for now this:

 

Calc Table = 
FILTER(
    FactCalls,
    RELATED(DimStatus[Names]) <> "drop out"
)

 


Just add why the DO in your result are still there after the removal and I'll add the logic


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors