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
Kpham
Resolver I
Resolver I

Agrupar y agregar el valor de la siguiente fila del grupo

Queridos todos,

Me gustaría transformar la mesa de:

Variable startdate
a15-5-1983
a10-1-1985
a8-8-1986
b11-6-1985
b12-9-1988

A esto: Donde el siguiente siguiente en el grupo es la fecha de finalización

VariablestartdateEnddate
a15-5-198310-1-1985
a10-1-19858-8-1986
a8-8-19861-1-1990
b11-6-198512-9-1988
b12-9-19881-10-1991

Creo que Group por en combinación con Index podría hacer el truco, pero no puedo averiguar cómo hacerlo. Preferiría agregar una columna adicional en la consulta

1 ACCEPTED SOLUTION
AlB
Super User
Super User

@Kpham

Coloque el siguiente código M en una consulta en blanco para ver los pasos, en función de los datos de ejemplo. Hace exactamente lo mismo que se mostró anteriormente:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUDA0CHUG0iBgqAAFvo4h8U6Owa5KOkpGpvqGBvpGBobmQI6xob6hkb4lECjF6tBDu4GhPhABtVsMhHYjM30DkwHTDne85UBpNydDu4d/sGtwvGFAKAWRj2wGuVFIbTPIjUys7qAgTKllBvlxa0SFuDWiQrxQzwzK4taICvFCXTOwxm0sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Variable key" = _t, #"Valid From" = _t, #"Valid To" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Variable key", type text}, {"Valid From", type date}, {"Valid To", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Variable key", Order.Ascending}, {"Valid From", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "enddate", each try if #"Added Index"[Variable key]{[Index]+1} = [Variable key] then #"Added Index"[Valid From]{[Index]+1} else [Valid To] otherwise [Valid To], type date),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

Por favor, marque la pregunta resuelta cuando haya terminado y considere dar un pulgar hacia arriba si las publicaciones son útiles.

Póngase en contacto conmigo de forma privada para obtener asistencia con cualquier necesidad de BI a gran escala, tutoría, etc.

Salud

SU18_powerbi_badge

View solution in original post

7 REPLIES 7
AlB
Super User
Super User

@Kpham

Coloque el siguiente código M en una consulta en blanco para ver los pasos, en función de los datos de ejemplo. Hace exactamente lo mismo que se mostró anteriormente:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUDA0CHUG0iBgqAAFvo4h8U6Owa5KOkpGpvqGBvpGBobmQI6xob6hkb4lECjF6tBDu4GhPhABtVsMhHYjM30DkwHTDne85UBpNydDu4d/sGtwvGFAKAWRj2wGuVFIbTPIjUys7qAgTKllBvlxa0SFuDWiQrxQzwzK4taICvFCXTOwxm0sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Variable key" = _t, #"Valid From" = _t, #"Valid To" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Variable key", type text}, {"Valid From", type date}, {"Valid To", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Variable key", Order.Ascending}, {"Valid From", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "enddate", each try if #"Added Index"[Variable key]{[Index]+1} = [Variable key] then #"Added Index"[Valid From]{[Index]+1} else [Valid To] otherwise [Valid To], type date),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

Por favor, marque la pregunta resuelta cuando haya terminado y considere dar un pulgar hacia arriba si las publicaciones son útiles.

Póngase en contacto conmigo de forma privada para obtener asistencia con cualquier necesidad de BI a gran escala, tutoría, etc.

Salud

SU18_powerbi_badge

Kpham
Resolver I
Resolver I

https://we.tl/t-pPZbzS6Ugh

Hola AIB aquí con el conjunto de datos

AlB
Super User
Super User

@Kpham

No entiendo la pregunta.

No puedo trabajar con capturas de pantalla. Necesitaría los datos pegados aquí en formato text-tabular. O el pbix

Por favor, marque la pregunta resuelta cuando haya terminado y considere dar un pulgar hacia arriba si las publicaciones son útiles.

Póngase en contacto conmigo de forma privada para obtener asistencia con cualquier necesidad de BI a gran escala, tutoría, etc.

Salud

SU18_powerbi_badge

AlB
Super User
Super User

Hola @Kpham

Coloque el siguiente código M en una consulta en blanco para ver los pasos.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("RcqxCQAgDATAXb72wSiROIuk0P2HkIhoe9wYmEgQpVK6VXi6kikh+sRoAe3AiiJsvxwp7CEG9w0=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Variable = _t, startdate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Variable", type text}, {"startdate", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Variable", Order.Ascending}, {"startdate", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "enddate", each try if #"Added Index"[Variable]{[Index]+1} = [Variable] then #"Added Index"[startdate]{[Index]+1} else null otherwise null)
in
    #"Added Custom"

Por favor, marque la pregunta resuelta cuando haya terminado y considere dar un pulgar hacia arriba si las publicaciones son útiles.

Póngase en contacto conmigo de forma privada para obtener asistencia con cualquier necesidad de BI a gran escala, tutoría, etc.

Salud

SU18_powerbi_badge

¿También tuvo en cuenta que quiero terminar la lógica después de la última fila del grupo. I este caso las variables se agrupan en a y b

@Kpham

Sí, con este bit:

if #"Added Index"[Variable]{[Index]+1} = [Variable]

Por favor, marque la pregunta resuelta cuando haya terminado y considere dar un pulgar hacia arriba si las publicaciones son útiles.

Póngase en contacto conmigo de forma privada para obtener asistencia con cualquier necesidad de BI a gran escala, tutoría, etc.

Salud

SU18_powerbi_badge

Kpham_1-1604761725965.png

Puedo obtener este resultado mediante el uso agrupado por e índice, pero ¿cómo puedo válido desde la fecha en otra fila

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.