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
WilliamAzevedo
Helper III
Helper III

Transform text lines into date columns

Hi.

 

I have a budget control that must show how much money was budgeted and how much was spent and compare both using a columns and line visual. The problem is my data has no date because the months with the budgeted and spent amount are columns. Here's what I mean (month abreviation is in portuguese):

I have:

ProjectBudget JanSpent JanBudget FevSpent FevBudget MarSpent MarBudget AbrSpentAbrBudget MaiSpentMaiBudget JunSpentJunBudget JulSpentJulBudget AgoSpentAgoBudget SetSpentSetBudget OutSpentOutBudget NovSpentNovBudget DezSpentDez
112.543,322.526,481.115,662.526,481.115,662.526,481.115,660,001.115,660,002.231,330,002.231,330,002.231,330,002.231,330,002.789,160,002.789,160,003.346,990,00
237.702,980,000,002.060,030,00271,760,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,00
30,000,003.188,931.294,623.188,911.819,483.188,910,003.188,910,006.377,820,006.377,820,006.377,820,006.377,820,007.972,280,007.972,280,009.566,730,00
40,000,002.212,991.095,882.212,98816,262.212,980,002.212,980,004.425,950,004.425,950,004.425,950,004.425,950,005.532,440,005.532,440,006.638,930,00
55.713.616,845.199,030,0022.813,240,0024.664,470,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,00

 

I need:

ProjectMonthBudgetSpent
1Jan12543,32526,48
1Fev1156,662526,48
5Nov0,000,00
5Dez0,000,00

 

And so on. How to do that in Power Query?

 

Thank you very much in advance!

1 ACCEPTED SOLUTION

Please try this @WilliamAzevedo
What I think the reason could be is, that your data does not seem to have strictly two rows for a particular project number and month i.e. The Budget and The Spent. Apart from these two, there are certain rows for a particular project number and month which are null as well that get picked up while expanding when just "Column1" and "Column2" are asked to be picked up by the code. I'll leave the changed code where I have tried remove any null values from the list after grouping ( List.RemoveNulls(_[Value]) ) which eventually expand just the rows with numbers. Thanks!

let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],


#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", Int64.Type}}),


#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project"}, "Attribute", "Value"),


Custom1 = Table.TransformColumns(#"Unpivoted Other Columns", {"Attribute", each Text.End(_,3)}),


#"Grouped Rows" = Table.Group(Custom1, {"Project", "Attribute"}, {{"All", each _[Value]}}),


Custom2 = Table.TransformColumns(#"Grouped Rows",{"All", each List.RemoveNulls(_)}),


#"Extracted Values" = Table.TransformColumns(Custom2, {"All", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),


#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "All", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"All.1", "All.2"}),


#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"All.1", type text}, {"All.2", type text}})


in


#"Changed Type1"

Sundar Rajagopalan

View solution in original post

19 REPLIES 19
WilliamAzevedo
Helper III
Helper III

Hello everyone and I'm sorry it took me so long to reply. I was out of the office those days and because of that I had neither worked on the task I asked help for, nor accessed the community.

So, today I had to make a change a in my model (SharePoint folder with .txt files as source instead of .xlsx files) and for that reason I think I have to ask: do the methods still apply? While this message reaches you, I will try it anyway.

Hi @WilliamAzevedo ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

v-priyankata
Community Support
Community Support

Hi @WilliamAzevedo 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

dufoq3
Super User
Super User

Hi @WilliamAzevedo, another solution:

 

Output

dufoq3_0-1742921675449.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZJZbsMwDETv4u8BIS7ichYj979GZaeNZSQwUBhovzR6oihSw3VdeMHCQt0UKkMPKQ7LDRNzh/svaUNrH4mQKEP1PokssF8RJTVH1Q95YF229jQomqDyCH3laD7k/E4wwt8C/3bZCte3IyXOROn+z1IGl4PullJyPa2Z6Pn2RJw0Ail3SVCFQPKKFHV3hM4d2gc7hOVpIFOrjsyDbjLZIX5m57sTMTLpqH6XdOoqMLsiTq7f3rz663tksJKPstP2LVed502GaQqZcomRu8Hiv6fw8QU=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Project = _t, #"Budget Jan" = _t, #"Spent Jan" = _t, #"Budget Fev" = _t, #"Spent Fev" = _t, #"Budget Mar" = _t, #"Spent Mar" = _t, #"Budget Abr" = _t, SpentAbr = _t, #"Budget Mai" = _t, SpentMai = _t, #"Budget Jun" = _t, SpentJun = _t, #"Budget Jul" = _t, SpentJul = _t, #"Budget Ago" = _t, SpentAgo = _t, #"Budget Set" = _t, SpentSet = _t, #"Budget Out" = _t, SpentOut = _t, #"Budget Nov" = _t, SpentNov = _t, #"Budget Dez" = _t, SpentDez = _t]),
    Unpivoted = Table.UnpivotOtherColumns(Source, {"Project"}, "Attribute", "Value"),
    ReplacedValue = Table.ReplaceValue(Unpivoted," ","",Replacer.ReplaceText,{"Attribute"}),
    SplitColumn = Table.SplitColumn(ReplacedValue, "Attribute", Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}), {"Attribute", "Month Name"}),
    Pivoted = Table.Pivot(SplitColumn, List.Distinct(SplitColumn[Attribute]), "Attribute", "Value"),
    Ad_Date = Table.AddColumn(Pivoted, "Date", each Date.FromText("2025" & [Month Name] & "01", [Format="yyyyMMMdd", Culture="pt-PT"]), type date)
in
    Ad_Date

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi!

 

I don't know what I did wrong, but the result was the unpivoted columns returning to pivoted.

Hi @WilliamAzevedo, if you don't know how to use my query - read note below my post.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

SundarRaj
Solution Supplier
Solution Supplier

Hi @WilliamAzevedo , here's a solution you could look at. I'll leave the code used below. Thanks!

let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],


#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", Int64.Type}, {"Budget Jan", type text}, {"Spent Jan", type text}, {"Budget Fev", type text}, {"Spent Fev", type text}, {"Budget Mar", type text}, {"Spent Mar", type text}, {"Budget Abr", type text}, {"SpentAbr", Int64.Type}, {"Budget Mai", type text}, {"SpentMai", Int64.Type}, {"Budget Jun", type text}, {"SpentJun", Int64.Type}, {"Budget Jul", type text}, {"SpentJul", Int64.Type}, {"Budget Ago", type text}, {"SpentAgo", Int64.Type}, {"Budget Set", type text}, {"SpentSet", Int64.Type}, {"Budget Out", type text}, {"SpentOut", Int64.Type}, {"Budget Nov", type text}, {"SpentNov", Int64.Type}, {"Budget Dez", type text}, {"SpentDez", Int64.Type}}),


#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project"}, "Attribute", "Value"),
Custom1 = Table.TransformColumns(#"Unpivoted Other Columns", {"Attribute", each Text.End(_,3)}),


#"Grouped Rows" = Table.Group(Custom1, {"Project", "Attribute"}, {{"All", each Table.FromRows({_[Value]})}}),


#"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Column1", "Column2"}, {"Column1", "Column2"}),


Custom2 = Table.RenameColumns(#"Expanded All", List.Zip({Table.ColumnNames(#"Expanded All"),{"Project","Month","Budget","Spent"}}))


in
Custom2

SundarRaj_0-1742891860853.png

 

Sundar Rajagopalan

Hi!

 

Since the data I posted was just an example, I'm having some difficulty on replicating the process to my actual data.

Until here:

#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project"}, "Attribute", "Value"),
Custom1 = Table.TransformColumns(#"Unpivoted Other Columns", {"Attribute", each Text.End(_,3)}),

I have this result:

WilliamAzevedo_0-1742911838312.png

 

But from here I couldn't figure how to make the "Spent" lines become a column. If I try this:

WilliamAzevedo_1-1742912285231.png

 

Here's the result:

WilliamAzevedo_2-1742912312479.png

 

And @lbendlin, I appreciate very much your help! I just need the "Spent" field to be a column in my table, so I can use it as a field in the graph and line visual instead of a matrix.

When you grouped the column and recieved the table in the column "Todos". The column that I extracted "Value", is the amount column name "Value" as well? If not, then change the _[ColumnName] that is _[Valor]. Post this, you can simply follow the next steps in the code. Let me know if this works. Thanks

Sundar Rajagopalan

It did not. And this time I tried to make eve the column names as similar to your instructions as possible:

WilliamAzevedo_0-1742922544571.png

 

The columns were created, but with values null (here I'm displaying the last rows, but al of them are null😞

WilliamAzevedo_1-1742922594887.png

 

@WilliamAzevedo , it seems the problem is at the Grouped Rows step. I hope you are getting a table which contains three columns i.e. "Invest", "Attributo" and "Valor" similar to the first image below.

In case after grouping you have the following table format, you'd only require the column which contains the number - _[ValueColumnName]

Please check if the grouped table is in the format below

 

Also do share the image of the error or the step of the "Table" of the grouped rows step

SundarRaj_0-1742926812636.png

 

Sundar Rajagopalan

It does result a Table column, but with four columns:

WilliamAzevedo_0-1742934569278.png

 

The view of a selected row:

WilliamAzevedo_1-1742934610555.png

 

The result when I expand the column using the expand button:

WilliamAzevedo_2-1742934673977.png

 

Result when I expand typing the code:

WilliamAzevedo_3-1742934874438.png

 

The code I typed:

WilliamAzevedo_4-1742934908077.png

 

@WilliamAzevedo , is it possible for you to send me your actual data that you are working with for better reference?

Sundar Rajagopalan

Unfortunately it's not 🙁.

But, as you can see, I have other data sources and for the help I'm asking here I'm working specifically with queries fZRIM0001 - Orçado x Realizado and it's derivate (linked), dMetas Mensais, which I'm asking help for. What if I send you the code for them?

 

fZRIM0001 - Orçado x Realizado

let
    Fonte = SharePoint.Files("https://company.sharepoint.com/sites/divisão", [ApiVersion = 15]),
    #"Linhas Filtradas" = Table.SelectRows(Fonte, each ([Folder Path] = "https://company.sharepoint.com/sites/divisão/Documentos Partilhados/Relatórios de Gestão/Rel_Inv - Orc_Real/")),
    #"Linhas Filtradas1" = Table.SelectRows(#"Linhas Filtradas", let latest = List.Max(#"Linhas Filtradas"[Date created]) in each [Date created] = latest),
    #"orc_x_real XLS xlsx_https://company sharepoint com/sites/divisão/Documentos Partilhados/Relatórios de Gestão/Rel_Inv - Orc_Real/" = #"Linhas Filtradas1"{[Name="orc_x_real.XLS.xlsx",#"Folder Path"="https://company.sharepoint.com/sites/divisão/Documentos Partilhados/Relatórios de Gestão/Rel_Inv - Orc_Real/"]}[Content],
    #"Pasta de Trabalho Importada do Excel" = Excel.Workbook(#"orc_x_real XLS xlsx_https://company sharepoint com/sites/divisão/Documentos Partilhados/Relatórios de Gestão/Rel_Inv - Orc_Real/"),
    orc_x_real_Sheet = #"Pasta de Trabalho Importada do Excel"{[Item="orc_x_real",Kind="Sheet"]}[Data],
    #"Colunas Removidas" = Table.RemoveColumns(orc_x_real_Sheet,{"Column1"}),
    #"Linhas Filtradas2" = Table.SelectRows(#"Colunas Removidas", each ([Column2] <> null)),
    #"Cabeçalhos Promovidos" = Table.PromoteHeaders(#"Linhas Filtradas2", [PromoteAllScalars=true]),
    #"Tipo Alterado" = Table.TransformColumnTypes(#"Cabeçalhos Promovidos",{{"Invest.", Int64.Type}, {"Descrição Investimento", type text}, {"Diret.", type text}, {"Aplic.", type text}, {"Descrição Finalidade", type text}, {"Unidade Gestora.", type text}, {"Sistema", type text}, {"Descrição Agrupamento", type text}, {"C. Pcte.", Int64.Type}, {"Descrição Pacote GMI", type text}, {"C.Munic.", type text}, {"Município", type text}, {"Fonte", type text}, {"Tipo de Fonte", type text}, {"Reaj.", type logical}, {"Exerc.", Int64.Type}, {"     Orç. Jan", type number}, {"  Real. Jan", type number}, {"  Orç. Fev", type number}, {"  Real. Fev", type number}, {"  Orç. Mar", type number}, {"  Real. Mar", type number}, {"  Orç. Abr", type number}, {"Real.Abr", Int64.Type}, {"  Orç. Mai", type number}, {"Real.Mai", Int64.Type}, {"  Orç. Jun", type number}, {"Real.Jun", Int64.Type}, {"  Orç. Jul", type number}, {"Real.Jul", Int64.Type}, {"  Orç. Ago", type number}, {"Real.Ago", Int64.Type}, {"  Orç. Set", type number}, {"Real.Set", Int64.Type}, {"   Orç. Out", type number}, {"Real.Out", Int64.Type}, {"   Orç. Nov", type number}, {"Real.Nov", Int64.Type}, {"     Orç. Dez", type number}, {"Real.Dez", Int64.Type}, {" Total Orçado", type number}, {"      Alocado", type number}, {"    Tot Real.", type number}, {" Saldo do PIE", type number}, {"   Saldo Aloc", type number}, {"Excluído", type text}, {"Tp Ct Del", type text}, {"Contrt. Deleg", type text}, {"Delegação", type text}, {"Programa", type text}, {"Cd. Fonte", Int64.Type}, {"CD TERRIT", Int64.Type}, {"Territ. Id", type text}, {"Semiárido", type text}, {"Microrregião", type text}, {"InvCap", type text}, {"Status Inv.", type text}, {"EVTE", type text}, {"ERNAM", type text}, {"ERDAT", Int64.Type}, {"AENAM", type text}, {"AEDAT", Int64.Type}, {"Tp.Invest.", Int64.Type}, {"Des.TpInv", type text}}),
    #"Linhas Classificadas" = Table.Sort(#"Tipo Alterado",{{"Invest.", Order.Ascending}}),
    #"Colunas Renomeadas" = Table.RenameColumns(#"Linhas Classificadas",{{"     Orç. Jan", "Orç. Jan"}, {"  Real. Jan", "Real. Jan"}, {"  Orç. Fev", "Orç. Fev"}, {"  Real. Fev", "Real. Fev"}, {"  Orç. Mar", "Orç. Mar"}, {"  Real. Mar", "Real. Mar"}, {"  Orç. Abr", "Orç. Abr"}, {"  Orç. Mai", "Orç. Mai"}, {"  Orç. Jun", "Orç. Jun"}, {"  Orç. Jul", "Orç. Jul"}, {"  Orç. Ago", "Orç. Ago"}, {"  Orç. Set", "Orç. Set"}, {"   Orç. Out", "Orç. Out"}, {"   Orç. Nov", "Orç. Nov"}, {"     Orç. Dez", "Orç. Dez"}, {" Total Orçado", "Total Orçado"}, {"      Alocado", "Alocado"}, {"    Tot Real.", "Tot Real."}, {" Saldo do PIE", "Saldo do PIE"}, {"   Saldo Aloc", "Saldo Aloc"}}),
    #"Tipo Alterado1" = Table.TransformColumnTypes(#"Colunas Renomeadas",{{"Orç. Jan", type number}, {"Real. Jan", type number}, {"Orç. Fev", type number}, {"Real. Fev", type number}, {"Orç. Mar", type number}, {"Real. Mar", type number}, {"Orç. Abr", type number}, {"Real.Abr", type number}, {"Orç. Mai", type number}, {"Real.Mai", type number}, {"Orç. Jun", type number}, {"Real.Jun", type number}, {"Orç. Jul", type number}, {"Real.Jul", type number}, {"Orç. Ago", type number}, {"Real.Ago", type number}, {"Orç. Set", type number}, {"Real.Set", type number}, {"Orç. Out", type number}, {"Real.Out", type number}, {"Orç. Nov", type number}, {"Real.Nov", type number}, {"Orç. Dez", type number}, {"Real.Dez", type number}}),
    #"Linhas Classificadas1" = Table.Sort(#"Tipo Alterado1",{{"Invest.", Order.Ascending}}),
    #"Erros Substituídos" = Table.ReplaceErrorValues(#"Linhas Classificadas1", {{"Reaj.", true}}),
    #"Colunas Renomeadas1" = Table.RenameColumns(#"Erros Substituídos",{{"Real.Abr", "Real. Abr"}, {"Real.Mai", "Real. Mai"}, {"Real.Jun", "Real. Jun"}, {"Real.Jul", "Real. Jul"}, {"Real.Ago", "Real. Ago"}, {"Real.Set", "Real. Set"}, {"Real.Out", "Real. Out"}, {"Real.Nov", "Real. Nov"}, {"Real.Dez", "Real. Dez"}})
in
    #"Colunas Renomeadas1"

 

dMetas Mensais (so far):

let
    Fonte = #"fZRIM0001 - Orçado x Realizado",
    #"Outras Colunas Removidas" = Table.SelectColumns(Fonte,{"Invest.", "Orç. Jan", "Real. Jan", "Orç. Fev", "Real. Fev", "Orç. Mar", "Real. Mar", "Orç. Abr", "Real. Abr", "Orç. Mai", "Real. Mai", "Orç. Jun", "Real. Jun", "Orç. Jul", "Real. Jul", "Orç. Ago", "Real. Ago", "Orç. Set", "Real. Set", "Orç. Out", "Real. Out", "Orç. Nov", "Real. Nov", "Orç. Dez", "Real. Dez"}),
    #"Outras Colunas Não Dinâmicas" = Table.UnpivotOtherColumns(#"Outras Colunas Removidas", {"Invest."}, "Atributo", "Valor"),
    #"Custom1" = Table.TransformColumns(#"Outras Colunas Não Dinâmicas", {"Atributo", each Text.End(_,3)}),
    #"Grouped Rows" = Table.Group(#"Custom1", {"Invest.", "Atributo"}, {{"Todos", each Table.FromRows({_[Valor]})}}),
    #"Expanded Todos" = Table.ExpandTableColumn(#"Grouped Rows", "Todos", {"Column1", "Clumn2"}, {"Column1", "Column2"})
in
    #"Expanded Todos"

Would it work? Thank you!

Please try this @WilliamAzevedo
What I think the reason could be is, that your data does not seem to have strictly two rows for a particular project number and month i.e. The Budget and The Spent. Apart from these two, there are certain rows for a particular project number and month which are null as well that get picked up while expanding when just "Column1" and "Column2" are asked to be picked up by the code. I'll leave the changed code where I have tried remove any null values from the list after grouping ( List.RemoveNulls(_[Value]) ) which eventually expand just the rows with numbers. Thanks!

let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],


#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", Int64.Type}}),


#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Project"}, "Attribute", "Value"),


Custom1 = Table.TransformColumns(#"Unpivoted Other Columns", {"Attribute", each Text.End(_,3)}),


#"Grouped Rows" = Table.Group(Custom1, {"Project", "Attribute"}, {{"All", each _[Value]}}),


Custom2 = Table.TransformColumns(#"Grouped Rows",{"All", each List.RemoveNulls(_)}),


#"Extracted Values" = Table.TransformColumns(Custom2, {"All", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),


#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "All", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"All.1", "All.2"}),


#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"All.1", type text}, {"All.2", type text}})


in


#"Changed Type1"

Sundar Rajagopalan


your data does not seem to have strictly two rows for a particular project number and month

You are correct, it does not have. The reason is that a project may or may not have it's values readjusted along time (thus some of them have). Sould I try it anyway?

hI @WilliamAzevedo , Sorry for the late response. Yes please try out the above code and see if it works as per your requirements. Thanks
Only if there are null values, it would work, but if those extra columns aren't null. What you can do is, while expanding don't use the code but do it manually so it automatically expands into X number of columns in your data.

SundarRaj_0-1744039650433.png

Instead of using the code which has just two columns, just expand it through the icon above, it will automatically expand into the number of columns that you have. Thanks!

Sundar Rajagopalan

It worked, thank you very much!

Also, thank you, @dufoq3, for showing another possibility!

lbendlin
Super User
Super User

Your source data is inconsistent. Sometimes there is a space after "Spent" and sometimes there is none.

 

After unpivoting and cleaning your data you can load it into Power BI

 

lbendlin_0-1742850782303.png

 

lbendlin_1-1742850889127.png

 

 

 

 

 

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.