Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
4 years ago

Valor total incorrecto DAX

¡Hola! Espero que alguien pueda ayudarme con esta pregunta.


FONDO:

Tengo dos tablas:

Calendario =

ADDCOLUMNS (

CALENDARIO (FECHA(2016,1,1), FECHA(AÑO(HOY())-1,12,31)),

"Año", AÑO ( [Fecha] ))

... y Encuesta:

Año

Ciudad

ID del encuestado

Pregunta 1a

Pregunta 1b

2020

Nombre de la ciudad1

123456

3

2

2020

Nombre de la ciudad1

123457

1

2020

Nombre de la ciudad1

123458

4

2020

Nombre de la ciudad1

123459

5

5


I have also created a column in Survey that has a many-to-one relationsship to Calendario:

Fechas = FECHA(Encuesta[Año],1,1)

MEDIDAS:

1a Número de encuestados =

CALCULAR(

DISTINCTCOUNT(Encuesta[ID del encuestado]),

Encuesta[Pregunta 1a] <> BLANK()

)

1a Número de encuestados (último valor) =

VAR NumberLY= CALCULATE([1a Número de encuestados], SAMEPERIODLASTYEAR(Calendar[Date]))

DEVOLUCIÓN

IF(ISBLANK([1a Número de encuestados]), Número, [1a Número de encuestados])


PREGUNTA:
If you choose a year in the report and a city has a value for [1a Number of respondents], you should see that value. But if it hasn't a value the chosen year, you should get the value from the year before. This works fine when I have a filter on cities. But when it comes to the total level, it only shows the values from the chosen year. How can I adjust my measure [1a Number of respondents (last value)] (or create a new measure) to show a mix of values from the chosen year and the year before?

EJEMPLO:
I select year 2020 in the report (from Calendario) and get the following result:

Ciudad

1a Número de encuestados (último valor)

Nombre de la ciudad2

170

Nombre de la ciudad3

166

Total

170


El valor de Cityname2 es de 2020 y el valor de Cityname3 es de 2019. El valor total debe ser 170 + 166 = 336 y no 170.


¡Gracias de antemano!

4 Replies

  • Hay @2FG ,

    Puede obtener el valor total correcto creando una nueva medida.

    Nueva medida = SUMX('TableName', [1a Número de encuestados (último valor)] )

    Luego pones la nueva medida en él, estoy seguro de que obtendrás esto.

    Ciudad

    1a Número de encuestados (último valor)

    Nueva medida

    Nombre de la ciudad2

    170

    170

    Nombre de la ciudad3

    166

    166

    Total

    170

    336

    Por favor, pruébalo.

    Saludos

    Esteban Tao

    Si esta publicación ayuda, considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      ¡Hola!

      No, lo siento, no funciona mientras tenga un filtro en el año. Entonces todavía obtengo 170 en el nivel total.

  • Hola @2FG ,

    ¿Puedes intentarlo?

    TEST =
    IF (
        HASONEVALUE ( SURVEY[CITY] ),
        [1a Number of respondents (last value)],
        SUMX ( VALUES ( SURVEY[CITY] ), [1a Number of respondents (last value)] )
    )

    Por favor, acéptelo como la solución si resuelve su problema. También se agradecen las felicitaciones.

    Bien

    Shishir

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Hola @Shishir22 ,
      Desafortunadamente eso tampoco funciona. Con esta medida, el valor de Cityname3 se queda en blanco y el total sigue siendo 170.