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
Anonymous
Not applicable

Cómo obtener la última causa de terminación de contrato mediante DAX (LAST_VALUE sobre partición en SQL)

Hola a todos,

Tengo esta tabla no ordenada que está enumerando para cada contractID todo el estado de este contrato.

anas-elkesri_0-1609555124832.png

Notará que un estado de contrato puede estar en Terminated y luego volver a "On-Going" y que la tabla no está ordenada por año

Quiero obtener como salida PARA CADA CONTRATO la razón de estado para la última vez que el ESTADO DEL CONTRATO ha sido TERMINADO.

SO i debe obtener estos valores para el ContractID 1 y 2.

IdEstado de la última terminación
1Por elección
2Jubilación

Sé que puedo conseguirlo usando SQL con algo como esto :

LastTerminationStatus á LAST_VALUE(StatusReason) OVER (PARTITION By ID ORDER By StatusDate) Where ContractStatus á "Terminated"

Pero realmente no sé cómo conseguirlo usando DAX. He intentado LASTNONBLANK pero esta fucción requiere una tabla ordenada que no es el caso aquí

Gracias por adelantado por su ayuda !!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@anas-elkesri aquí hay dos medidas que pueden obtener el resultado

Last Terminate Reason Method 1 = 
CALCULATE (
    MAX ( 'Last Terminate'[Status Reason] ),
    TOPN ( 1, FILTER ( ALLEXCEPT ( 'Last Terminate', 'Last Terminate'[Id] ), 'Last Terminate'[Contract Status] = "Terminated" ), [Status Date], DESC )
)

Last Terminate Reason Method 2 = 
VAR __table = FILTER ( ALLEXCEPT ( 'Last Terminate', 'Last Terminate'[Id] ), 'Last Terminate'[Contract Status] = "Terminated"  ) 
VAR __lastDate = CALCULATE ( MAX (  'Last Terminate'[Status Date] ), __table )
RETURN
CALCULATE (
    MAX ( 'Last Terminate'[Status Reason] ),
    __table,
    'Last Terminate'[Status Date] = __lastDate
)

Consulta mi última entrada de blog Año-2020, Pandemia, Power BI y más allá para obtener un resumen de mis versiones favoritas de las características de Power BI en 2020

Me gustaría elogios si mi solución ayudara. 👉 Si puedes dedicar tiempo a publicar la pregunta, también puedes hacer esfuerzos para dar Felicitaciones a quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos en https://perytus.com, su ventanilla única para proyectos/formación/consulta relacionadas con Power BI.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@anas-elkesri aquí hay dos medidas que pueden obtener el resultado

Last Terminate Reason Method 1 = 
CALCULATE (
    MAX ( 'Last Terminate'[Status Reason] ),
    TOPN ( 1, FILTER ( ALLEXCEPT ( 'Last Terminate', 'Last Terminate'[Id] ), 'Last Terminate'[Contract Status] = "Terminated" ), [Status Date], DESC )
)

Last Terminate Reason Method 2 = 
VAR __table = FILTER ( ALLEXCEPT ( 'Last Terminate', 'Last Terminate'[Id] ), 'Last Terminate'[Contract Status] = "Terminated"  ) 
VAR __lastDate = CALCULATE ( MAX (  'Last Terminate'[Status Date] ), __table )
RETURN
CALCULATE (
    MAX ( 'Last Terminate'[Status Reason] ),
    __table,
    'Last Terminate'[Status Date] = __lastDate
)

Consulta mi última entrada de blog Año-2020, Pandemia, Power BI y más allá para obtener un resumen de mis versiones favoritas de las características de Power BI en 2020

Me gustaría elogios si mi solución ayudara. 👉 Si puedes dedicar tiempo a publicar la pregunta, también puedes hacer esfuerzos para dar Felicitaciones a quien haya ayudado a resolver tu problema. ¡Es una muestra de agradecimiento!

Visítenos en https://perytus.com, su ventanilla única para proyectos/formación/consulta relacionadas con Power BI.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Muchas gracias por su respuesta.

El primer método no me dio el resultado que quería. Pero el segundo funcionó perfectamente y también es un método bastante agradable. Así que gracias de nuevo !! 🙂

amitchandak
Super User
Super User

@anas-elkesri , compruebe si una de las medidas puede funcionar para usted

measure: calculate(lastnonblankvalue(Table[status_date], max(Table[contract_status])))


measure: calculate(lastnonblankvalue(Table[status_date], max(Table[contract_status])) allexcept(Table[ID]))

measure- calculate(max(Table[contract_status]), filter(Table,Table[status_date] - calculate(max(Table[status_date]), allexpcept(Table,table[ID]))))

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.