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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
RolandPlanet
Frequent Visitor

¿Cómo obtengo el valor X superior en las columnas de cada fila?

Hola

Estoy tratando de agregar una columna donde obtengo el primer valor más que ocurre en las columnas de una fila junto con el segundo valor más que ocurre, y el tercer valor más probable

IdColumna1Columna2Columna3Columna4Columna5
1234manzanamanzanaNaranjamanzanaNaranja
1235NaranjaNaranjaPeraNaranjaNaranja

En otras palabras, me gustaría una columna que mostraría "Apple" como el primer valor más que ocurre y "Naranja" como el segundo valor más que ocurre en la primera fila. ¿Cómo puedo hacer eso?

1 ACCEPTED SOLUTION

Hola, @RolandPlanet

He hecho algunos cambios en la medida. Por favor, pruebe la siguiente medida para ver si funciona.

Result = 
var _id = SELECTEDVALUE('Table'[ID])
var tab = 
SUMMARIZE(
    'Table',
    'Table'[ID],
    'Table'[Value],
    "Count",
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Value] = EARLIER('Table'[Value])
        )
    )
)
var newtab = 
ADDCOLUMNS(
    tab,
    "Rank",
    RANKX(
        FILTER(
            tab,
            [ID] = _id
        ),
        [Count]
    )
)
return
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 1
    ),
    [Value],
    "-"
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 2
    ),
    [Value],
    "-"
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 3
    ),
    [Value],
    "-"
)

Saludos

Allan

Si este post ayuda,entonces 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

4 REPLIES 4
v-alq-msft
Community Support
Community Support

Hola, @RolandPlanet

Puede ir al Editor de consultas, ir a la cinta de opciones 'Transformar', hacer 'ID' seleccionado y hacer clic en 'despivotar otras columnas'. Y luego tienes que hacer clic en 'Cerrar y aplicar'.

I1.png

Puede crear una medida como se muestra a continuación.

Result = 
var _id = SELECTEDVALUE('Table'[ID])
var tab = 
SUMMARIZE(
    'Table',
    'Table'[ID],
    'Table'[Value],
    "Count",
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Value] = EARLIER('Table'[Value])
        )
    )
)
var newtab = 
ADDCOLUMNS(
    tab,
    "Rank",
    RANKX(
        FILTER(
            tab,
            [ID] = _id
        ),
        [Count]
    )
)
return
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 1
    ),
    [Value]
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 2
    ),
    [Value]
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 3
    ),
    [Value]
)

Resultado:

I2.png

Saludos

Allan

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

¡Esto es genial! Sin embargo, si dos valores tienen el mismo número de ocurrencias, se concatenan juntos como "AppleOrange", por ejemplo. ¿Hay alguna manera de prevenir esto?

Hola, @RolandPlanet

He hecho algunos cambios en la medida. Por favor, pruebe la siguiente medida para ver si funciona.

Result = 
var _id = SELECTEDVALUE('Table'[ID])
var tab = 
SUMMARIZE(
    'Table',
    'Table'[ID],
    'Table'[Value],
    "Count",
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Value] = EARLIER('Table'[Value])
        )
    )
)
var newtab = 
ADDCOLUMNS(
    tab,
    "Rank",
    RANKX(
        FILTER(
            tab,
            [ID] = _id
        ),
        [Count]
    )
)
return
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 1
    ),
    [Value],
    "-"
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 2
    ),
    [Value],
    "-"
)&" "&
CONCATENATEX(
    FILTER(
        newtab,
        [Rank] = 3
    ),
    [Value],
    "-"
)

Saludos

Allan

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

amitchandak
Super User
Super User

@RolandPlanet

Mejor que los datos despivotados

https://radacad.com/pivot-and-unpivot-with-power-bi

A continuación, puede utilizar todas las expectativas a nivel de identificación para obtener esta respuesta

https://www.sqlbi.com/articles/managing-all-functions-in-dax-all-allselected-allnoblankrow-allexcept...

https://community.powerbi.com/t5/Desktop/Percentage-of-subtotal/td-p/95390

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors
Top Kudoed Authors