Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Syndicate_Admin
Administrator
Administrator

Fechas de duplicación de filas entre la fecha más antigua y la fecha más tardía de una tabla

Hola

Tengo una tabla de datos como se muestra a continuación en el editor de Power Query.


Material , Fecha, Texto, Lugar, Cantidad. Precio
X1 01.01.2023 AADD Top 88000 130262
X1 01.01.2024 AADD Top 66000 99220
X1 01.02.2023 AADD Top 110000 154022
X1 01.02.2024 AADD Top 88000 127028
X1 01.09.2024 AADD Top 3164 17402
X2 01.01.2023 ABAB Top 66000 133643,4
X2 01.01.2024 ABAB Top 36000 73198,8
X2 01.02.2023 ABAB Top 66000 125947,8
X2 01.02.2024 ABAB Top 56660 111166,92
X2 01.12.2024 ABAB Top 1050 5103
X3 01.01.2023 QWER Top 84000 283080
X3 01.01.2024 QWER Top 0 0
X3 01.02.2023 QWER Top 0 0
X3 01.02.2024 QWER Top 42000 128520
X3 01.11.2024 QWER Top 1578 6458
X4 14.02.2023 RTZE Top 3159 16790,1
X4 01.03.2024 RTZE Top 6300 30863,7

Para cada material en los datos anteriores, quiero agregar filas duplicadas para cada material con cada primera fecha del mes entre las fechas más tempranas y más tardías , con las columnas Texto y Lugar siendo las mismas para un material en particular, pero las columnas Cantidad y Precio deben ser cero para estas filas duplicadas.

Por ejemplo, como en los datos anteriores, para el material X4 tengo datos con la fecha más temprana el 14..02.2023 y la fecha más reciente 01.03.2024 pero no tengo ningún dato entre estas fechas para el material X4, pero quiero agregar/duplicar datos para todas las fechas entre las fechas más tempranas y más tardías con las columnas Texto y Lugar siendo las mismas con las columnas Cantidad y Precio deben ser 0.

¿Cómo puedo hacerlo solo en el editor de Power Query de Power BI y todos los datos deben estar en una sola tabla?

Intenté usar la opción de fusión creando una nueva tabla, pero solo puedo hacerlo para uno en el material de mis datos como se muestra a continuación, por ejemplo, pero lo quiero para todos los materiales de la misma manera ...

The8_0-1714136067960.png

¿Alguna sugerencia?

¡¡Gracias!!




2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Hola

No estoy al tanto del resultado esperado. Muestra el resultado esperado para X3 y X4.

Syndicate_Admin
Administrator
Administrator

No estoy exactamente seguro de por qué necesitaría torturar sus datos de esa manera, pero aquí va:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJda8IwFAbgvxJ6HeR85POyUi8HU4SNSS+KeFGQbUgH279fWk0tmARDoUkbHt5zksOheumG06XvzmIcTViI+9iffodp8nrujuOP7U/3OfTD32r8dumPp6qVh2ra8o7TC3AVHgLisKjrprlCX9/RdA4AxgkykKE8oDKAMTdAeE8ESYBKCRDhKqBWQOkEVEowlyCQLJBLCr4kMBoV09gQYiFQoo3rei3ybUBmo1iqPKJyCM+IsIzeSZdE6MkkoR/aK1tSslG0CU48IERjpE+2BcsMgoaZROAFwQ+d3b5tdg+CU3M55Bgc5AmVIeYEt2VSoFKI54VcBkWLU3GakgQWy0BtXZwbpZener29qO5l7PYfm7h5YYSrrn30jPUg8YEZa+FbkBxjOFYjwpkYlrZq238=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Split Column by Positions" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByPositions({0, 12,  24,  34,  45,54}), {"Column1.1", "Column1.2", "Column1.3", "Column1.4", "Column1.5", "Column1.6"}),
    #"Trimmed Text" = Table.TransformColumns(#"Split Column by Positions",{{"Column1.1", Text.Trim, type text}, {"Column1.2", Text.Trim, type text}, {"Column1.3", Text.Trim, type text}, {"Column1.4", Text.Trim, type text}, {"Column1.5", Text.Trim, type text}, {"Column1.6", Text.Trim, type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Trimmed Text", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}},"de"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Material", "Text", "Place"}, {{"Date", each {Int64.From(List.Min([Date]))..Int64.From(List.Max([Date]))}, type list}}),
    #"Expanded Dates" = Table.ExpandListColumn(#"Grouped Rows", "Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Date", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each Date.Day([Date])=1),
    #"Merged Queries" = Table.NestedJoin(#"Filtered Rows", {"Material", "Text", "Place", "Date"}, #"Changed Type", {"Material", "Text", "Place", "Date"}, "Filtered Rows", JoinKind.FullOuter),
    #"Expanded Filtered Rows" = Table.ExpandTableColumn(#"Merged Queries", "Filtered Rows", {"Material", "Date", "Text", "Place", "Quantity.", "Price"}, {"Material.1", "Date.1", "Text.1", "Place.1", "Quantity.", "Price"}),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Filtered Rows",null,each [Material.1],Replacer.ReplaceValue,{"Material"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,each [Text.1],Replacer.ReplaceValue,{"Text"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1",null,each [Place.1],Replacer.ReplaceValue,{"Place"}),
    #"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2",null,each [Date.1],Replacer.ReplaceValue,{"Date"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Replaced Value3",{"Material", "Text", "Place", "Date", "Quantity.", "Price"}),
    #"Replaced Value4" = Table.ReplaceValue(#"Removed Other Columns",null,"0",Replacer.ReplaceValue,{"Quantity.","Price"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Replaced Value4",{ {"Date", type date}, {"Place", type text}, {"Text", type text}, {"Material", type text}}),
    #"Changed Type3" = Table.TransformColumnTypes(#"Changed Type2",{{"Quantity.", type number}, {"Price", type number}},"nl")
in
    #"Changed Type3"

Cómo usar este código: Crear una nueva consulta en blanco. Haga clic en "Editor avanzado". Reemplace el código de la ventana por el código que se proporciona aquí. Haga clic en "Listo". Una vez que haya examinado el código, reemplace el paso Origen por su propio código fuente.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors