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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Syndicate_Admin
Administrator
Administrator

Diferentes cálculos de DAX basados en valores seleccionados

Hola Comunidad,
Estoy teniendo un problema al crear una medida para hacer diferentes cálculos dependiendo del centro de coste seleccionado, a continuación se muestra un ejemplo de datos

Valor CC
8031
1102
1203
8035

Mi lógica es que si se selecciona 803 en una segmentación de datos de centro de coste, tendría un cálculo medio, si algo que no es 803, entonces suma de los valores del centro de coste. Creé la medida a continuación:

Test Measure = 
VAR selectedValues =
    VALUES ( Test[Cost Center] )
RETURN
    IF (
        CONTAINS ( selectedValues, Test[Cost Center], "803" ),
        CALCULATE ( SUM ( Test[Value] ), Test[Cost Center] <> "803" ) + CALCULATE ( AVG ( Test[Value] ), Test[Cost Center] = "803" ),
        CALCULATE ( SUM ( Test[Value] ) )
    )

Esto funciona bien si se seleccionan algunos valores en la segmentación de datos; sin embargo, si no se selecciona ninguno o se seleccionan todos los valores, daría el cálculo incorrecto. Cualquier dirección o ayuda sería realmente apreciada!

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

Por favor, intente esto:

Test Measure = 
VAR selectedValues =
    VALUES ('Table'[CC])
RETURN
    IF (
        CONTAINS ( selectedValues, 'Table'[CC], 803 ),
        CALCULATE(AVERAGE('Table'[value]),ALLSELECTED('Table'[CC])),
        CALCULATE ( SUM ('Table'[value] ) )
    )

Vlianlmsft_0-1624341586024.png

View solution in original post

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Por favor, intente esto:

Test Measure = 
VAR selectedValues =
    VALUES ('Table'[CC])
RETURN
    IF (
        CONTAINS ( selectedValues, 'Table'[CC], 803 ),
        CALCULATE(AVERAGE('Table'[value]),ALLSELECTED('Table'[CC])),
        CALCULATE ( SUM ('Table'[value] ) )
    )

Vlianlmsft_0-1624341586024.png

Syndicate_Admin
Administrator
Administrator

Pruebe algo a lo largo de las líneas de IF(SELECTEDVALUE(CostCenter) = 803, [hacer algo], [hacer algo más])

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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