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: Expandir 1 Registro w/StartDate y EndDate a muchos Registros (uno para cada día entre)

Hola

¡Todos ustedes han sido increíbles! ¡Muchas gracias por su ayuda!

En el futuro con mi proyecto, el siguiente obstáculo que he alcanzado es en torno a la transformación de los datos que he recibido para nuestra herramienta de planificación. Estoy recibiendo una sola fila que quiero expandir en fechas individuales. Soy nuevo en la manipulación de datos en Power BI, cualquier comentario sería apreciado! @ImkeF, he visto mención de que eres un mago de m. Fuiste una ayuda increíble la última vez, ¿alguna idea aquí?

Formato actual

RecordID          StartDate          EndDate          DaysBetween      HoursPerDay
12345             1/1/2020           1/3/2020         3                8
12346             3/1/2020           1/4/2020         4                6

Formato deseado

Date        RecordID        Hours
1/1/2020    12345           8
1/2/2020    12345           8
1/3/2020    12345           8
3/1/2020    12346           6
3/2/2020    12346           6
3/3/2020    12346           6
3/4/2020    12346           6

Puntos de bonificación si puede establecer sáb / sol a 0! Imagino que puedo manejar eso agregando otra columna, pero todavía trabajando en mi proceso allí.

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hola

Este código M funciona

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RecordID", Int64.Type}, {"StartDate", type datetime}, {"EndDate", type datetime}, {"DaysBetween", Int64.Type}, {"HoursPerDay", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"DaysBetween"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Date", each {Number.From([StartDate])..Number.From([EndDate])}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Date",{"StartDate", "EndDate"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Date", "RecordID", "HoursPerDay"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Date", type date}})
in
    #"Changed Type1"

Espero que esto ayude.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ya estaba trabajando en esto y noté nuevo post cuando volví a publicar esto. Probablemente el mismo enfoque, pero en caso de que no ...

Dejar
Fuente: Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQYNjFV0lEy1DfUNzIwMgAzjWFMYyC2UIrVgagzA4kgqzOBMU2A2EwpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t á ((texto de tipo) meta [Serialized.Text ? true]) en la tabla de tipos [RecordID - _t, StartDate , _t, EndDate , _t, Days8etween , _t, HoursPerDay , _t]),
"Tipo modificado con configuración regional" á Table.TransformColumnTypes(Source, ?"StartDate", fecha de tipo, "EndDate", fecha de tipo, "en-150"),
"Tipo modificado" á Table.TransformColumnTypes("Tipo modificado con configuración regional", "Days8etween", Int64.Type, "HoursPerDay", Int64.Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, Int64,Type, In
"Añadido personalizado" - Table.AddColumn('Tipo cambiado', "DateList", cada List.Dates([StartDate],[Days8etween],#duration(1,0,0,0))),
"Columnas eliminadas" ? Table.RemoveColumns('Added Custom',''StartDate','EndDate'', 'Days8etween''),
"Expanded DateList" á Table.ExpandListColumn(?"Columnas eliminadas", "Lista de fechas"),
"Changed Type1" ? Table.TransformColumnTypes("Expanded DateList","DateList", fecha de tipo, fecha de tipo),
"Columnas reordenadas" - Table.ReorderColumns('Changed Type1','DateList'', "RecordID", "HoursPerDay"'),
"Columnas renombradas" ? Table.RenameColumns("Columnas reordenadas", "FechaLista", "Fecha", "HorasPerday", "Horas")
En
"Columnas renombradas"

Si esto funciona para usted, por favor márquelo como solución. Los felicitaciones también son apreciados. Por favor, avísame si no.

saludos

palmadita





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Como siempre... esta comunidad es genial!

Hice algunos pequeños ajustes, pero quería adjuntar mi versión como referencia. Específicamente, fildré cuando el intervalo de fechas wsa no se definió, así como 0 fines de semana fuera. Gracias de nuevo por toda la ayuda! ¡Esto fue un salvavidas!

let
    Source = #"Project Plan",
    #"FilteredSource" = Table.SelectRows(#"Source", each ([Business Days Per Period] > 0)),

    #"Changed Type" = Table.TransformColumnTypes(#"FilteredSource",{{"EmployeeID", type text}, {"Period Start Date", type datetime}, {"Period End Date", type datetime}, {"Business Days Per Period", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Business Days Per Period"}),
    #"Added Custom" = Table.AddColumn(#"Removed Columns", "Date", each {Number.From([Period Start Date])..Number.From([Period End Date])}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Date",{"Period Start Date", "Period End Date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Date", "EmployeeID", "periodHrs"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Date", type date}}),
    //#"Reordered Columns1" = Table.ReorderColumns(#"Changed Type1",{"Date", "ProjectID", "PlanID", "WeekNbr", "HoursPerDay", "hardbooked", "assignmentID", "taskID", "periodCost", "periodBill", "costrate", "billingrate", "Project Start Date", "Project End Date", "Total Days Per Period", "EmployeeID", "PrjEmpID"}),
    #"Removed Columns2" = Table.RemoveColumns(#"Changed Type1",{"PlanID","WeekNbr"}),
    #"Reordered Columns2" = Table.ReorderColumns(#"Removed Columns2",{"Date", "ProjectID", "EmployeeID", "HoursPerDay",  "hardbooked", "assignmentID", "taskID", "periodCost", "periodBill", "costrate", "billingrate", "Project Start Date", "Project End Date", "Total Days Per Period", "PrjEmpID"}),
    #"Removed Columns3" = Table.RemoveColumns(#"Reordered Columns2",{"hardbooked", "assignmentID", "taskID", "periodCost", "periodBill", "costrate", "billingrate", "Project Start Date", "Project End Date", "Total Days Per Period", "PrjEmpID"}),
    #"Removed Columns4" = Table.RemoveColumns(#"Removed Columns3",{"periodHrs"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns4", "Day Of Week", each 
    
    if Date.DayOfWeek([Date])=0 then "Sun" else
    if Date.DayOfWeek([Date])=1 then "Mon" else
    if Date.DayOfWeek([Date])=2 then "Tue" else
    if Date.DayOfWeek([Date])=3 then "Wed" else
    if Date.DayOfWeek([Date])=4 then "Thur" else
    if Date.DayOfWeek([Date])=5 then "Fri" else
    if Date.DayOfWeek([Date])=6 then "Sat" else "???"),

    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Weekend?", each if Date.DayOfWeek([Date])=0 or Date.DayOfWeek([Date])=6 then "Y" else "N"),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "NewHours", each if [#"Weekend?"] = "Y" then 0 else [HoursPerDay]),
    #"Removed Columns0" = Table.RemoveColumns(#"Added Custom3",{"HoursPerDay"}),
    #"Changed Type1a" = Table.TransformColumnTypes(#"Removed Columns0",{{"EmployeeID", type text}}),
    #"Added Custom4" = Table.AddColumn(#"Changed Type1a", "WeekNbr", each Date.WeekOfYear([Date])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom4",{{"WeekNbr", type text}}),
    #"Added Custom5" = Table.AddColumn(#"Changed Type2", "Month", each Date.MonthName([Date])),
    #"Reordered Columns0" = Table.ReorderColumns(#"Added Custom5",{"Month", "WeekNbr", "Day Of Week", "Date", "ProjectID", "EmployeeID", "NewHours", "Weekend?"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns0",{{"NewHours", "Hours"}})
    
in
    #"Renamed Columns"

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.