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
Nickb167
Frequent Visitor

Obtención de valor para la segunda última fecha en la tabla relacionada.

Hola

Tengo un conjunto de datos que aparece como se muestra a continuación:

IdFechaPuntuación
11/01/20203
31/01/20202
41/01/20205
61/01/20204
12/02/20202
32/02/20203
42/02/20205
62/02/20201
13/03/20205
33/03/20203
43/03/20204
63/03/20201
14/04/20202
34/04/20205
44/04/20202
64/04/20204

El resultado esperado es:

IdPrimera puntuaciónPuntuación más recienteSegunda puntuación más reciente
1325
3253
4524
6441

He trabajado en la primera y última puntuación con:

Puntuación más reciente: SUMX(
VALUES(cnsw_carersstar[cnsw_ProgramParticipant]),
CALCULATE(MAX(cnsw_carersstar[CarersStarScore]), LASTDATE(cnsw_carersstar[DateOnly]))
)
Pero estoy teniendo dificultad para conseguir el segundo último. He intentado añadir filtros a lo anterior, pero no parece obtener el resultado esperado. Cualquier ayuda sería muy apreciada.
Gracias
Nick
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hola @Nickb167 ,

Según mi opinión, desea mostrar Score basado en la última fecha, la segunda fecha más reciente y la primera fecha, ¿verdad?

Puede usar la siguiente fórmula:

rank =
RANKX (
    FILTER (
        ALL ( LastDateTable ),
        'LastDateTable'[ID] = MAX ( 'LastDateTable'[ID] )
    ),
    CALCULATE ( MAX ( ( LastDateTable[Date] ) ) ),
    ,
    ASC
)
First Score =
CALCULATE ( MAX ( LastDateTable[Score] ), FILTER ( LastDateTable, [rank] = 1 ) )
Last Score =
CALCULATE (
    MAX ( 'LastDateTable'[Score] ),
    FILTER ( 'LastDateTable', [rank] = MAXX ( ALL ( LastDateTable ), [rank] ) )
)
Second Last Score =
CALCULATE (
    MAX ( 'LastDateTable'[Score] ),
    FILTER ( 'LastDateTable', [rank] = MAXX ( ALL ( LastDateTable ), [rank] - 1 ) )
)

Mi visualización tiene este aspecto:

9.15.1.1.png

¿He respondido a tu pregunta? Por favor, marque mi respuesta como solución. Muchas gracias.

Si no es así, cargue algunas muestras de datos insensibles y la salida esperada.

Saludos

Eyelyn Qin

View solution in original post

3 REPLIES 3
v-eqin-msft
Community Support
Community Support

Hola @Nickb167 ,

Según mi opinión, desea mostrar Score basado en la última fecha, la segunda fecha más reciente y la primera fecha, ¿verdad?

Puede usar la siguiente fórmula:

rank =
RANKX (
    FILTER (
        ALL ( LastDateTable ),
        'LastDateTable'[ID] = MAX ( 'LastDateTable'[ID] )
    ),
    CALCULATE ( MAX ( ( LastDateTable[Date] ) ) ),
    ,
    ASC
)
First Score =
CALCULATE ( MAX ( LastDateTable[Score] ), FILTER ( LastDateTable, [rank] = 1 ) )
Last Score =
CALCULATE (
    MAX ( 'LastDateTable'[Score] ),
    FILTER ( 'LastDateTable', [rank] = MAXX ( ALL ( LastDateTable ), [rank] ) )
)
Second Last Score =
CALCULATE (
    MAX ( 'LastDateTable'[Score] ),
    FILTER ( 'LastDateTable', [rank] = MAXX ( ALL ( LastDateTable ), [rank] - 1 ) )
)

Mi visualización tiene este aspecto:

9.15.1.1.png

¿He respondido a tu pregunta? Por favor, marque mi respuesta como solución. Muchas gracias.

Si no es así, cargue algunas muestras de datos insensibles y la salida esperada.

Saludos

Eyelyn Qin

AiolosZhao
Memorable Member
Memorable Member

Hola @Nickb167 ,

Creo que la siguiente tabla es lo que quieres:

Getting value for second last date in related table.PNG

Agredo una columna de índice en la tabla y las medidas son:

First Score = CALCULATE(SUM('Table (2)'[Score]), FILTER(ALL('Table (2)'[ID],'Table (2)'[Index]),'Table (2)'[Index] = MIN('Table (2)'[Index])))
Last Score = CALCULATE(SUM('Table (2)'[Score]), FILTER(ALL('Table (2)'[ID],'Table (2)'[Index]),'Table (2)'[Index] = MAX('Table (2)'[Index])))
Second Last Score = CALCULATE(SUM('Table (2)'[Score]), FILTER(ALL('Table (2)'[ID],'Table (2)'[Index]),'Table (2)'[Index] = MAXX(FILTER('Table (2)','Table (2)'[Index] < MAX('Table (2)'[Index])),'Table (2)'[Index])))

Mesa:

Getting value for second last date in related table 2.PNGGetting value for second last date in related table 3.PNG

Por favor, inténtelo.

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@Nickb167 ,

Tratar

last á lastnonblankvalue(Table[Date], sum(Table[Score]))
Segundo último ?
var _max á maxx(allselected(Date[Date]), Date[Date])
devolución
calculate(lastnonblankvalue(Table[Date], sum(Table[Score])), filter(allselected(Table), Table[Date] <_max))


First - Firstnonblankvalue(Table[Date], sum(Table[Score]))
En segundo lugar,
var _max á maxx(allselected(Date[Date]), Date[Date])
devolución
calculate(Firstnonblankvalue(Table[Date], sum(Table[Score])), filter(allselected(Table), Table[Date] <_max))

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.