Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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:
Project | Budget Jan | Spent Jan | Budget Fev | Spent Fev | Budget Mar | Spent Mar | Budget Abr | SpentAbr | Budget Mai | SpentMai | Budget Jun | SpentJun | Budget Jul | SpentJul | Budget Ago | SpentAgo | Budget Set | SpentSet | Budget Out | SpentOut | Budget Nov | SpentNov | Budget Dez | SpentDez |
1 | 12.543,32 | 2.526,48 | 1.115,66 | 2.526,48 | 1.115,66 | 2.526,48 | 1.115,66 | 0,00 | 1.115,66 | 0,00 | 2.231,33 | 0,00 | 2.231,33 | 0,00 | 2.231,33 | 0,00 | 2.231,33 | 0,00 | 2.789,16 | 0,00 | 2.789,16 | 0,00 | 3.346,99 | 0,00 |
2 | 37.702,98 | 0,00 | 0,00 | 2.060,03 | 0,00 | 271,76 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 |
3 | 0,00 | 0,00 | 3.188,93 | 1.294,62 | 3.188,91 | 1.819,48 | 3.188,91 | 0,00 | 3.188,91 | 0,00 | 6.377,82 | 0,00 | 6.377,82 | 0,00 | 6.377,82 | 0,00 | 6.377,82 | 0,00 | 7.972,28 | 0,00 | 7.972,28 | 0,00 | 9.566,73 | 0,00 |
4 | 0,00 | 0,00 | 2.212,99 | 1.095,88 | 2.212,98 | 816,26 | 2.212,98 | 0,00 | 2.212,98 | 0,00 | 4.425,95 | 0,00 | 4.425,95 | 0,00 | 4.425,95 | 0,00 | 4.425,95 | 0,00 | 5.532,44 | 0,00 | 5.532,44 | 0,00 | 6.638,93 | 0,00 |
5 | 5.713.616,84 | 5.199,03 | 0,00 | 22.813,24 | 0,00 | 24.664,47 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 | 0,00 |
I need:
Project | Month | Budget | Spent |
1 | Jan | 12543,3 | 2526,48 |
1 | Fev | 1156,66 | 2526,48 |
… | … | … | … |
5 | Nov | 0,00 | 0,00 |
5 | Dez | 0,00 | 0,00 |
And so on. How to do that in Power Query?
Thank you very much in advance!
Solved! Go to 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"
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.
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.
Hi @WilliamAzevedo, another solution:
Output
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
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.
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
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:
But from here I couldn't figure how to make the "Spent" lines become a column. If I try this:
Here's the result:
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
It did not. And this time I tried to make eve the column names as similar to your instructions as possible:
The columns were created, but with values null (here I'm displaying the last rows, but al of them are null😞
@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
It does result a Table column, but with four columns:
The view of a selected row:
The result when I expand the column using the expand button:
Result when I expand typing the code:
The code I typed:
@WilliamAzevedo , is it possible for you to send me your actual data that you are working with for better reference?
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"
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.
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!
It worked, thank you very much!
Also, thank you, @dufoq3, for showing another possibility!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
13 | |
10 | |
8 | |
7 |
User | Count |
---|---|
17 | |
10 | |
7 | |
6 | |
6 |