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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Cálculo de promedio ponderado

Hola

He alcanzado un bloqueo de carretera y busco ayuda en el cálculo de la media ponderada para los siguientes datos.

El riesgo de columna2 determina qué productos están en una categoría de riesgo y se calcula de la siguiente manera

Risk2 = if(([Consumption]) > [Forecast],0,1)

Sospecho que hay una mejor manera de calcular la relación de elementos "Riesgo" para cada subcategoría (A-C). Intenté usar ALLSELECTED[GROUP] pero alguna razón por la que no funcionó. Aquí está la medida calculada que usé

% = DIVIDE(sum([Risk2]), calculate(COUNT([Risk2]),ALLSELECTED([ITEMCODE])))

Y luego el resultado final que estoy tratando de lograr es el promedio ponderado
El Grupo A tiene un 50% de weght,

Grupo B - 30%

Grupo C - 20%
y los grupos restantes (D-F) son 0%.

Necesito obtener la suma de % de cada grupo multiplicado por peso - 60*0.5 + 93.75*0.3 + 80*0.2 á 74.25

La medida actual es una simple declaración IF, pero eso no parece funcionar

Weighted % = 
VAR FR = 
DIVIDE(sum([Risk2]), calculate(COUNT([Risk2]),ALLSELECTED([ITEMCODE])))
RETURN
IF(MAX([GROUP] )= "A",FR * 0.5, 
IF (MAX([GROUP]) = "B", FR * 0.3,
IF( MAX([GROUP]) = "C", FR * 0.2, 
IF( MAX([GROUP]) = "D", FR * 0,
IF( MAX([GROUP]) = "E", FR * 0,
IF( MAX([GROUP]) = "F", FR * 0,FR * 0
))))))

Gracias

rigosakhx_0-1604863715719.png

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

Debe proporcionar un contexto de fila para que esto funcione cuando hay más de un grupo seleccionado.

Intente usar:

Weighted % = 
VAR FR = 
DIVIDE(sum([Risk2]), calculate(COUNT([Risk2]),ALLSELECTED([ITEMCODE])))
RETURN
SUMX(VALUES([GROUP]), 
SWITCH([Group]
, "A",FR * 0.5 
, "B", FR * 0.3
, "C", FR * 0.2
, "D", FR * 0
, "E", FR * 0
,"F", FR * 0
,FR * 0
)
)

Además, es probable que pueda utilizar la función AVERAGE en lugar de DIVIDE, SUM y COUNT.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

4 REPLIES 4
AllisonKennedy
Super User
Super User

@rigosakhx Eso se ve bonito y elegante. Bien hecho, y de nada. 🙂


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Actualización - según AllisonKennedy reemplazó DIVIDE SUM COUNT con AVERAGE y creó una medida separada para él.

% - AVG[Riesgo2]

Entonces no necesitaba usar VAR en mi medida final


% ponderado ?
SUMX(VALUES([GROUP]),
SWITCH([Grupo]
, "A",AVG * 0,5
, "B", AVG * 0,3
, "C", AVG * 0,2
,AVG* 0
))

El código tiene más sentido y funciona según lo previsto

Muchas gracias a AllisonKennedy

Anonymous
Not applicable

Hola @AllisonKennedy
Gracias por esto
Casi funcionó - pero por alguna razón la suma es igual a la relación no ponderada



AllisonKennedy
Super User
Super User

Debe proporcionar un contexto de fila para que esto funcione cuando hay más de un grupo seleccionado.

Intente usar:

Weighted % = 
VAR FR = 
DIVIDE(sum([Risk2]), calculate(COUNT([Risk2]),ALLSELECTED([ITEMCODE])))
RETURN
SUMX(VALUES([GROUP]), 
SWITCH([Group]
, "A",FR * 0.5 
, "B", FR * 0.3
, "C", FR * 0.2
, "D", FR * 0
, "E", FR * 0
,"F", FR * 0
,FR * 0
)
)

Además, es probable que pueda utilizar la función AVERAGE en lugar de DIVIDE, SUM y COUNT.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors