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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Syndicate_Admin
Administrator
Administrator

Uso de DAX para crear una nueva columna basada en grupos dentro de la tabla

Hola

Las 7 columnas de la izquierda son parte de una tabla más grande que debo usar para obtener el resultado deseado en la columna de resultado requerido para cada fila de mi tabla.

Necesito ignorar los campos en blanco y, si todos los campos restantes contienen los mismos datos, devuelva ese valor en la columna de resultados. Si los campos restantes no contienen los mismos datos, el resultado debe ser "Mixto".

JanCronje16_0-1736739940520.png

Cualquier ayuda será agradecida.

Gracias

Ene

2 ACCEPTED SOLUTIONS
Syndicate_Admin
Administrator
Administrator

Hola @JanCronje16

Pruebe esto:

Output =
// Define a variable `_TBL` to create a virtual table with specified columns
VAR _TBL = {
    'Table'[Column1],
    // Column 1 from the table
    'Table'[Column2],
    // Column 2 from the table
    'Table'[Column3],
    // Column 3 from the table
    'Table'[Column4],
    // Column 4 from the table
    'Table'[Column5] // Column 5 from the table
} // Calculate the count of unique non-blank values in `_TBL`
VAR UniqueCount =
    COUNTROWS (
        // Count the number of rows in the resulting table
        DISTINCT (
            // Extract unique values from the filtered table
            FILTER (
                // Filter out blank values from `_TBL`
                _TBL,
                NOT ( ISBLANK ( [Value] ) ) // Keep rows where [Value] is not blank
            )
        )
    ) // Return the result based on the count of unique values
RETURN
    IF (
        UniqueCount > 1,
        // If there is more than 1 unique non-blank value
        "Mixed",
        // Return "Mixed"
        MAXX ( _TBL, [Value] ) // Otherwise, return the maximum value in `_TBL`
    )

danextian_0-1736745582609.png

View solution in original post

Gracias, funciona muy bien.

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Hola @JanCronje16 , Pruebe esto:

Result = 
VAR NonBlankValues = 
    UNION(
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column1])) && 'Table'[Column1] = EARLIER('Table'[Column1])), "Value", 'Table'[Column1]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column2])) && 'Table'[Column2] = EARLIER('Table'[Column2])), "Value", 'Table'[Column2]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column3])) && 'Table'[Column3] = EARLIER('Table'[Column3])), "Value", 'Table'[Column3]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column4])) && 'Table'[Column4] = EARLIER('Table'[Column4])), "Value", 'Table'[Column4]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column5])) && 'Table'[Column5] = EARLIER('Table'[Column5])), "Value", 'Table'[Column5]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column6])) && 'Table'[Column6] = EARLIER('Table'[Column6])), "Value", 'Table'[Column6]),
        SELECTCOLUMNS(FILTER(ALL('Table'), NOT(ISBLANK('Table'[Column7])) && 'Table'[Column7] = EARLIER('Table'[Column7])), "Value", 'Table'[Column7])
    )
VAR DistinctNonBlankValues = 
    FILTER(
        DISTINCT(NonBlankValues),
        [Value] <> BLANK()
    )
VAR FirstValue = MAXX(DistinctNonBlankValues, [Value])
VAR AllSame = 
    COUNTROWS(
        FILTER(
            DistinctNonBlankValues,
            [Value] <> FirstValue
        )
    ) = 0

RETURN
    IF(
        COUNTROWS(DistinctNonBlankValues) = 0,
        BLANK(),
        IF(
            AllSame,
            FirstValue,
            "Mixed"
        )
    )

Cambie los nombres de las columnas según corresponda.

Salidas:

shafiz_p_0-1736748683044.png



¡Espero que esto ayude!

Si esto resolvió su problema, ¡acéptelo como una solución y felicitaciones!

Saludos
Shahariar Hafiz

Syndicate_Admin
Administrator
Administrator

Hola @JanCronje16

Pruebe esto:

Output =
// Define a variable `_TBL` to create a virtual table with specified columns
VAR _TBL = {
    'Table'[Column1],
    // Column 1 from the table
    'Table'[Column2],
    // Column 2 from the table
    'Table'[Column3],
    // Column 3 from the table
    'Table'[Column4],
    // Column 4 from the table
    'Table'[Column5] // Column 5 from the table
} // Calculate the count of unique non-blank values in `_TBL`
VAR UniqueCount =
    COUNTROWS (
        // Count the number of rows in the resulting table
        DISTINCT (
            // Extract unique values from the filtered table
            FILTER (
                // Filter out blank values from `_TBL`
                _TBL,
                NOT ( ISBLANK ( [Value] ) ) // Keep rows where [Value] is not blank
            )
        )
    ) // Return the result based on the count of unique values
RETURN
    IF (
        UniqueCount > 1,
        // If there is more than 1 unique non-blank value
        "Mixed",
        // Return "Mixed"
        MAXX ( _TBL, [Value] ) // Otherwise, return the maximum value in `_TBL`
    )

danextian_0-1736745582609.png

Gracias, funciona muy bien.

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors
Top Kudoed Authors