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.
Queridos todos,
Me gustaría transformar la mesa de:
Variable | startdate |
a | 15-5-1983 |
a | 10-1-1985 |
a | 8-8-1986 |
b | 11-6-1985 |
b | 12-9-1988 |
A esto: Donde el siguiente siguiente en el grupo es la fecha de finalización
Variable | startdate | Enddate |
a | 15-5-1983 | 10-1-1985 |
a | 10-1-1985 | 8-8-1986 |
a | 8-8-1986 | 1-1-1990 |
b | 11-6-1985 | 12-9-1988 |
b | 12-9-1988 | 1-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
Solved! Go to Solution.
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
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
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
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
¿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
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
Puedo obtener este resultado mediante el uso agrupado por e índice, pero ¿cómo puedo válido desde la fecha en otra fila
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
1 |