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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
marcelocostafil
Frequent Visitor

Transformar tempo entre datas em linhas

Olá!

 

Desculpem, não sei como clarificar o tema no assunto, mas basicamente tenho uma tabela que possui duas colunas:

 - Uma coluna de Data de criação do processo.

 - Outra coluna de data de "fim" do processo.

 

Porém, eu preciso que cada dia entre a data início e data fim sejam transformados em linhas.

 

Abaixo um print do modelo atual:

Coluna da esquerda é a data de criação, e a coluna da direita é a data de fim.

marcelocostafil_0-1720084074171.png

Ou seja, se o processo abriu no dia 16/01/2023 e fechou no dia 19/01/2023, eu teria 4 linhas para este processo (16/01, 17/01, 18/01 e 19/01).

No caso da data fim estar vazia, queria que existisse uma linha para cada dia que passou entre o início do processo até hoje, já que o processo ainda não foi fechado.

 

O resultado final ficaria assim:

As linhas se mantém, e existiria uma coluna com a data de controle.

marcelocostafil_1-1720084329475.png

 

Se houver uma solução para isso, ou se precisarem de mais detalhes, fico à disposição.

 

Muito obrigado!

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Boa tarde @marcelocostafil ,

 

Deves adicionar uma nova coluna calculada com o seguinte código:

try { Number.From (Date.From ([Data])) ..
 Number.From(Date.From ([DataSaid]))}

 otherwise

 { Number.From (Date.From ([Data])) ..
 Number.From(Date.From (DateTime.LocalNow()))}

Depois expandes a coluna e formatas com data:

MFelix_1-1720098495922.png

Atenção que no caso de a coluna Data ser maior que o dia de hoje o código dá nulo:

MFelix_2-1720098596572.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTTNzDUNzIwMlYwNLQyMrQyNFPSUXJ29PMEUYl5mYeXJ+YAma4hrkDSycWnOCUxLa04JS0FyDUEYQuEASZWJhZWpuYgUUuEqKmVibmViYFSrE60ElDQwBwkbkKMdWkpxRC7ivFaBjHZjCYmxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, CodPorto = _t, CodPortoDesc = _t, Carregador = _t, Referencia = _t, Confirmado = _t, #"Data confi" = _t, DataSaid = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type datetime}, {"CodPorto", type text}, {"CodPortoDesc", type text}, {"Carregador", type text}, {"Referencia", type text}, {"Confirmado", Int64.Type}, {"Data confi", type datetime}, {"DataSaid", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each try { Number.From (Date.From ([Data])) ..
 Number.From(Date.From ([DataSaid]))}

 otherwise

 { Number.From (Date.From ([Data])) ..
 Number.From(Date.From (DateTime.LocalNow()))}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}})
in
    #"Changed Type1"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Boa tarde @marcelocostafil ,

 

Deves adicionar uma nova coluna calculada com o seguinte código:

try { Number.From (Date.From ([Data])) ..
 Number.From(Date.From ([DataSaid]))}

 otherwise

 { Number.From (Date.From ([Data])) ..
 Number.From(Date.From (DateTime.LocalNow()))}

Depois expandes a coluna e formatas com data:

MFelix_1-1720098495922.png

Atenção que no caso de a coluna Data ser maior que o dia de hoje o código dá nulo:

MFelix_2-1720098596572.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTTNzDUNzIwMlYwNLQyMrQyNFPSUXJ29PMEUYl5mYeXJ+YAma4hrkDSycWnOCUxLa04JS0FyDUEYQuEASZWJhZWpuYgUUuEqKmVibmViYFSrE60ElDQwBwkbkKMdWkpxRC7ivFaBjHZjCYmxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t, CodPorto = _t, CodPortoDesc = _t, Carregador = _t, Referencia = _t, Confirmado = _t, #"Data confi" = _t, DataSaid = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type datetime}, {"CodPorto", type text}, {"CodPortoDesc", type text}, {"Carregador", type text}, {"Referencia", type text}, {"Confirmado", Int64.Type}, {"Data confi", type datetime}, {"DataSaid", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each try { Number.From (Date.From ([Data])) ..
 Number.From(Date.From ([DataSaid]))}

 otherwise

 { Number.From (Date.From ([Data])) ..
 Number.From(Date.From (DateTime.LocalNow()))}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}})
in
    #"Changed Type1"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Olá, @MFelix

Era isto mesmo!

 

Muito obrigado pela ajuda!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.