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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TVR0927
Frequent Visitor

Eliminación de una fila en función de las condiciones de otras columnas y filas

Tengo lo que parece una situación complicada. Tengo un total de datos, pero aquí hay una muestra.

Mis criterios:

Si Inv Rec está en blanco, pero Combo tiene un Inv Rec en cualquier otra fila, elimine la fila con el Inv Rec en blanco (2a fila tendría que eliminarse)

Si Inv Rec está en blanco, pero ninguno de los Combos tiene un Inv Rec en ninguna otra fila, mantenga la fila (las últimas 2 filas tendrían que permanecer)

Los factores que siguen eliminando las filas son el paquete y la cantidad total, que se miran en POWERBI como no duplicados, así que no puedo simplemente decir eliminar los duplicados y no puedo averiguar cómo separarlos. Cualquier ayuda sería apreciada. Realmente espero que esto tenga sentido, ya que he estado luchando con esto por un par de semanas. ¡Gracias!

Sku

Md

Planta

Combo

Paquete

CANTIDAD TOTAL

INV REC

106020116

Abcd

1301

1301106020116ABCD

11688758

5148

300006828

106020116

Abcd

1301

1301106020116ABCD

11688751

4796

106020116

Abcd

1301

1301106020116ABCD

11688760

5148

300006828

106020118

CDEF

1301

1301106020118CDEF

11688546

4925

300006850

106020118

CDEF

1301

1301106020118CDEF

11688547

4925

300006850

106028884

EFGH

1301

1301106028884EFGH

11703440

5148

106028884

EFGH

1301

1301106028884EFGH

11703447

5148

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hola @TVR0927 ,

Puedo proporcionar dos soluciones para lograr esto:

1. Cree una columna calsulada como akutt mencionada y filtre:

Tag = 
IF(
    'Table'[INV REC] <> BLANK(),
    "REC",
    IF(
        COUNTROWS(
            FILTER(
                'Table',
                'Table'[SKU] = EARLIER('Table'[SKU])&&
                'Table'[MD] = EARLIER('Table'[MD])&&
                'Table'[PLANT] = EARLIER('Table'[PLANT])&&
                'Table'[COMBO] = EARLIER('Table'[COMBO])&&
                'Table'[BUNDLE] = EARLIER('Table'[BUNDLE])&&
                'Table'[TOTAL QUANTITY] = EARLIER('Table'[TOTAL QUANTITY])&&
                'Table'[INV REC] = EARLIER('Table'[INV REC])
            )
        )>1,
        "Stayed",
        "Removed"
    )
)​

r1.png

2. Utilice la consulta de alimentación con el código M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rc9LDsMgDEXRvTDOwA9s8zJs8+seoux/GwWpVauKZpCEiQVXOsLrGiAuUQAPXbjdh7EMJMFrtCqczEaDslyTlOOMDFt3XIPmvr6eQVx2v1TLME5zW/uuVTN17aN9NJNTWv6vkdRSpnl5NLSfiixJ9b3pRcj2BA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SKU = _t, MD = _t, PLANT = _t, COMBO = _t, BUNDLE = _t, #"TOTAL QUANTITY" = _t, #"INV REC" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SKU", Int64.Type}, {"MD", type text}, {"PLANT", Int64.Type}, {"COMBO", Int64.Type}, {"BUNDLE", type text}, {"TOTAL QUANTITY", Int64.Type}, {"INV REC", Int64.Type}}),
    Custom2 = Table.AddColumn(
        #"Changed Type","count",each 
            let 
                sku=[SKU],md=[MD],plant=[PLANT],combo=[COMBO],bundle=[BUNDLE],totalquantity=[TOTAL QUANTITY],invrec=[INV REC] 
            in 
                Table.RowCount(
                    Table.SelectRows(
                        #"Changed Type",each [SKU]=sku and [MD]=md and [PLANT]=plant and [COMBO]=combo and [BUNDLE]=bundle and [TOTAL QUANTITY]=totalquantity and [INV REC]=invrec
                    )
                )
    ),
    Custom3 = Table.SelectRows(Custom2,each [INV REC]<>null or [count]<>1),
    #"Removed Columns" = Table.RemoveColumns(Custom3,{"count"})
in
    #"Removed Columns"​

r2.png

Se adjunta un archivo de ejemplo que dependiendo de su situación específica (la tabla se utiliza DAX y Query1 se utiliza la consulta de energía), por favor compruébelo y pruébelo: Eliminación de una fila basada en condiciones en otras columnas y rows.pbix

Best Looks,
Yingjie Li

Si este post ayuda, por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

View solution in original post

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hola @TVR0927 ,

Puedo proporcionar dos soluciones para lograr esto:

1. Cree una columna calsulada como akutt mencionada y filtre:

Tag = 
IF(
    'Table'[INV REC] <> BLANK(),
    "REC",
    IF(
        COUNTROWS(
            FILTER(
                'Table',
                'Table'[SKU] = EARLIER('Table'[SKU])&&
                'Table'[MD] = EARLIER('Table'[MD])&&
                'Table'[PLANT] = EARLIER('Table'[PLANT])&&
                'Table'[COMBO] = EARLIER('Table'[COMBO])&&
                'Table'[BUNDLE] = EARLIER('Table'[BUNDLE])&&
                'Table'[TOTAL QUANTITY] = EARLIER('Table'[TOTAL QUANTITY])&&
                'Table'[INV REC] = EARLIER('Table'[INV REC])
            )
        )>1,
        "Stayed",
        "Removed"
    )
)​

r1.png

2. Utilice la consulta de alimentación con el código M:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rc9LDsMgDEXRvTDOwA9s8zJs8+seoux/GwWpVauKZpCEiQVXOsLrGiAuUQAPXbjdh7EMJMFrtCqczEaDslyTlOOMDFt3XIPmvr6eQVx2v1TLME5zW/uuVTN17aN9NJNTWv6vkdRSpnl5NLSfiixJ9b3pRcj2BA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [SKU = _t, MD = _t, PLANT = _t, COMBO = _t, BUNDLE = _t, #"TOTAL QUANTITY" = _t, #"INV REC" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SKU", Int64.Type}, {"MD", type text}, {"PLANT", Int64.Type}, {"COMBO", Int64.Type}, {"BUNDLE", type text}, {"TOTAL QUANTITY", Int64.Type}, {"INV REC", Int64.Type}}),
    Custom2 = Table.AddColumn(
        #"Changed Type","count",each 
            let 
                sku=[SKU],md=[MD],plant=[PLANT],combo=[COMBO],bundle=[BUNDLE],totalquantity=[TOTAL QUANTITY],invrec=[INV REC] 
            in 
                Table.RowCount(
                    Table.SelectRows(
                        #"Changed Type",each [SKU]=sku and [MD]=md and [PLANT]=plant and [COMBO]=combo and [BUNDLE]=bundle and [TOTAL QUANTITY]=totalquantity and [INV REC]=invrec
                    )
                )
    ),
    Custom3 = Table.SelectRows(Custom2,each [INV REC]<>null or [count]<>1),
    #"Removed Columns" = Table.RemoveColumns(Custom3,{"count"})
in
    #"Removed Columns"​

r2.png

Se adjunta un archivo de ejemplo que dependiendo de su situación específica (la tabla se utiliza DAX y Query1 se utiliza la consulta de energía), por favor compruébelo y pruébelo: Eliminación de una fila basada en condiciones en otras columnas y rows.pbix

Best Looks,
Yingjie Li

Si este post ayuda, por favor considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Anonymous
Not applicable

Es posible que pueda agregar otra columna con instrucciones If/elseif en la consulta power con las condiciones en las que Y es la fila debe permanecer y N es la fila no debe permanecer.

A continuación, simplemente filtre esa columna para la Y y cargue la salida de nuevo en powerBI.

No soy lo suficientemente hábil en IF statemetns para esto. Me encantaría cualquier sugerencia. ¿Cómo se escribe una instrucción if para una condición en otra columna y otra fila?

Si Combo es un duplicado y ninguna otra fila tiene un Inv Rec en blanco, entonces Y

Y

si Combo es duplicado e Inv Rec en otra fila no está en blanco entonces X?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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