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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Syndicate_Admin
Administrator
Administrator

Promedio de un campo basado en la condición de otra columna

Hola, necesito ayuda en DAX mientras calculo el promedio de Ecode. La condición sería si el recuento del código S coincide con el recuento distinto del código E, excluirá al calcular el promedio. Si el recuento del código S no coincide con el recuento distinto del código E, entonces tomará un recuento distinto del código E y, en base a eso, necesito calcular el promedio. ¿Cuál debería ser el enfoque? Cualquier ayuda sería realmente apreciada.Shown here how it would be calculatedShown here how it would be calculatedAquí se muestra cómo se calcularía

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

¿Es esto lo que estás buscando?

Control = VAR _DisE =DISTINCTCOUNT('Table'[E Code])
          VAR _CounS = COUNT('Table'[S Code]) 
          VAR _Cont = IF(_DisE<> _CounS,_DisE)
RETURN
_Cont

Flag = IF([Control],1,0)


Final = var _t1 = SUMX(VALUES('Table'[S Code]),[Control])
        VAR _t2 = SUMX(VALUES('Table'[S Code]),[Flag])
RETURN
_t1/_t2

Archivo PBIX de muestra adjunto
https://dropmefiles.com/EJ14P

Screen Capture #265.png

Hola, esta es la solución exacta que estaba buscando. Muchas gracias.

Syndicate_Admin
Administrator
Administrator

Este es un enfoque para resolver el problema en DAX:

  1. Create a calculated column that checks if the count of S code matches the distinct count of E code.

    Coincidencia = CONTAR(S_Code) = DISTINCTCOUNT(E_Code)

    1. Create another calculated column to get the count of distinct E code based on the previous calculated column.
      E_Code_Count = IF([Match]=TRUE(),0,DISTINCTCOUNT(E_Code))

      1. Create a measure to calculate the average of E code based on the previous calculated column.

        Avg_E_Code = AVERAGEX(FILTER(ALL(Table),[E_Code_Count]>0),[E_Code])

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.