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

Power Query - Fila anterior anidada

Hola

Estoy intentando obtener la fecha de pedido anterior en la siguiente columna para cada cliente en Power Query (no DAX).

1pbic.png

Leí un tutorial y sugirieron usar esta sintaxis, pero no es para datos anidados (agrupados). ¿Podría ayudarme a encontrar la solución? Gracias

1a.png

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

Este es el post que usé para hacer referencia por primera vez a la fila anterior en Power Query: https://www.myonlinetraininghub.com/referencing-next-row-power-query

Necesitará una columna de índice y también tendrá que agregar una condición de que MemberID - prev MemberID

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hola @Sunflower ,

Por favor, consulte :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMLTUN9Q3VIrVQREwQhcwBgsYwQRM9A1NUUVMMUTMoMYaIykxQBUxB4vEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MemberID = _t, Order = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"MemberID", Int64.Type}, {"Order", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"MemberID"}, {{"Data", each _, type table [MemberID=number, Order=date]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data],"index",0,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MemberID", "Data"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"MemberID", "Order", "index"}, {"Custom.MemberID", "Custom.Order", "Custom.index"}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Expanded Custom", "Custom.index", "Custom.index - Copy"),
    #"Renamed Columns" = Table.RenameColumns(#"Duplicated Column",{{"Custom.index - Copy", "index+1"}}),
    #"Added to Column" = Table.TransformColumns(#"Renamed Columns", {{"index+1", each _ + 1, type number}}),
    #"Merged Queries" = Table.NestedJoin(#"Added to Column", {"Custom.index", "Custom.MemberID"}, #"Added to Column", {"index+1", "Custom.MemberID"}, "Added to Column", JoinKind.LeftOuter),
    #"Expanded Added to Column" = Table.ExpandTableColumn(#"Merged Queries", "Added to Column", {"Custom.Order"}, {"Added to Column.Custom.Order"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Added to Column",{{"Custom.MemberID", Order.Ascending}, {"Custom.index", Order.Ascending}}),
    #"Renamed Columns1" = Table.RenameColumns(#"Sorted Rows",{{"Custom.MemberID", "MemberID"}, {"Custom.Order", "Order"}, {"Added to Column.Custom.Order", "PreviousOrder"}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns1",{"Custom.index", "index+1"})
in
    #"Removed Columns1"

Capture.PNG

Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

Saludos

Dedmon Dai

amitchandak
Super User
Super User

@Sunflower , Use esto un nuevo colum

maxx(filter(table,[memberID]-earlier([memberID]) && [order] <earlier([Order])),[Order])

Opciones de medida y columna discutidas aquí

https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5c3243d...

AllisonKennedy
Super User
Super User

Este es el post que usé para hacer referencia por primera vez a la fila anterior en Power Query: https://www.myonlinetraininghub.com/referencing-next-row-power-query

Necesitará una columna de índice y también tendrá que agregar una condición de que MemberID - prev MemberID

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.