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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

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

Top Kudoed Authors