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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

¿Cómo calculamos los rangos de las filas de la tabla dinámicamente con ALLSELECTED?

Hola

Tengo un modelo llamado "DAS Performance", que presenta KPIs para cada periodo (año-mes) y cada empleado.

Para cada período y rol del empleado, creé una columna calculada que clasifica su rendimiento en comparación con todos los empleados en ese período.

Fíjate en las columnas marcadas en amarillo, son importantes:

haimh_0-1736593109567.png

El código para el rango calculado es :

RANK_MONTHLY_CALLS = 
IF(
    'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0 && 
    'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative",
    RANKX(
        FILTER(
            ALL('DAS Performance'),  -- This will consider only the filtered employees
            'DAS Performance'[MONTH_CALANDER_ID] = EARLIER('DAS Performance'[MONTH_CALANDER_ID]) &&  -- Filter by the same month
            'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0 &&  -- Only include employees with total calls > 0
            'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative"  -- Only for Sales Representatives
        ),
        'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS],  -- Rank based on the total calls
        ,
        DESC,  -- Sort in descending order (highest calls get rank 1)
        DENSE  -- Use dense ranking (no gaps in ranks)
    ),
    BLANK()  -- Return blank if conditions are not met
)

La columna funciona muy bien y dependo de esta columna en otras medidas.

El problema comienza cuando empiezo a usar segmentaciones de equipo / DAS (DAS = Empleado)

Si filtro el objeto visual por segmentación con un equipo específico, por ejemplo, todos los equipos siguen calculando la columna de clasificación.

Traté de pensar en cómo resolver esto con ALLSELECTED, pero me enfrenté a 2 problemas:

1) Trabajo con el nivel de fila, por lo tanto, no hay función CALCULATE en mi rango.

2) Sé que necesito una función ALLSELECTED, pero requiere CALCULATE en una medida, no en una columna calculada.

Este código, por supuesto, no funcionó:

RANK_MONTHLY_CALLS_MEASURE = 
IF(
    'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0 && 
    'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative",
    RANKX(
        FILTER(
            ALLSELECTED('DAS Performance'),  -- This ensures we only rank based on the current filter context (like selected employees)
            'DAS Performance'[MONTH_CALANDER_ID] = MAX('DAS Performance'[MONTH_CALANDER_ID]) &&  -- Ensure ranking is done by month
            'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0 &&  -- Only employees with positive calls
            'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative"  -- Ensure ranking is only for Sales Representatives
        ),
        'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS],  -- Ranking based on total calls
        ,
        DESC,  -- Highest calls get rank 1
        DENSE  -- Use dense ranking (no gaps in ranks)
    ),
    BLANK()  -- Return blank for non-representatives or zero calls
)

¿Cómo resolver este problema, entonces, si me baso en una tabla estática (modelo)

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Hola, @haimh

No puede calcular el cálculo dinámico en la columna, en la columna una vez que ocurre la lógica / cálculo, no se puede modificar como selección de segmentación, por lo que debe ir con Medir.

RANK_MONTHLY_CALLS_measure =
VAR curr_MONTH_CALANDER_ID =
    SELECTEDVALUE ( 'DAS Performance'[MONTH_CALANDER_ID] )
RETURN
    IF (
        'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0
            && 'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative",
        RANKX (
            FILTER (
                ALLSELECTED ( 'DAS Performance' ),
                -- This will consider only the filtered employees
                'DAS Performance'[MONTH_CALANDER_ID] = curr_MONTH_CALANDER_ID
                    && -- Filter by the same month
                'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] > 0
                    && -- Only include employees with total calls > 0
                'DAS Performance'[GLOBAL_ROLE_CODE] = "Sales Representative" -- Only for Sales Representatives
            ),
            CALCULATE ( SUM ( 'DAS Performance'[TOTAL_F2F_VIDEO_MONTHLY_CALLS] ) ),
            ,
            DESC,
            -- Sort in descending order (highest calls get rank 1)
            DENSE -- Use dense ranking (no gaps in ranks)
        ),
        BLANK () -- Return blank if conditions are not met
    )

Saludos
Dangar

Si esta publicación ayuda, considere Acéptalo como la solución para ayudar a los demás miembros a encontrarlo más rápidamente.



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

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