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 some tables with different number of column with prefix "Level"
Example:
Table1 - Level1, Level2, Level3
Table2 - Level1, Level2, Level3, Level4
I want make sure all tables have Level1 ~ Level10.
How can I do that with powerquery? Thanks!
Solved! Go to Solution.
Hi @Anonymous
What are the values in those newly created columns? Here is one sample to have the same value with the column name
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkktLlHSwUbFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [level1 = _t, level2 = _t, level3 = _t, level4 = _t]),
columnList = {"level1","level2","level3","level4","level5","level6","level7","level8","level9","level10"},
fxAddColumn = (T as table, N as number) =>
[
newColumns=List.Difference(columnList, Table.ColumnNames(Source)),
counter = List.Count(newColumns),
columnName = newColumns{N},
tempTable = Table.AddColumn(T, columnName, each columnName),
result = if N>= counter-1 then tempTable else @fxAddColumn(tempTable,N+1)
][result],
Custom = fxAddColumn(Source,0)
in
Custom
let
Source = #table(List.Transform({1..10}, each "Level" & Text.From(_)), {}),
Other = #table({"Level1","Level3","Level5"},{{1,3,5}}),
Appended = Source & Other
in
Appended
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi @Anonymous
What are the values in those newly created columns? Here is one sample to have the same value with the column name
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkktLlHSwUbFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [level1 = _t, level2 = _t, level3 = _t, level4 = _t]),
columnList = {"level1","level2","level3","level4","level5","level6","level7","level8","level9","level10"},
fxAddColumn = (T as table, N as number) =>
[
newColumns=List.Difference(columnList, Table.ColumnNames(Source)),
counter = List.Count(newColumns),
columnName = newColumns{N},
tempTable = Table.AddColumn(T, columnName, each columnName),
result = if N>= counter-1 then tempTable else @fxAddColumn(tempTable,N+1)
][result],
Custom = fxAddColumn(Source,0)
in
Custom
I prefer all values of new created columns are setted as null. Thanks!
Hi @Anonymous
modify this line a little bit
tempTable = Table.AddColumn(T, columnName, each null),
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 |
---|---|
9 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
12 | |
11 | |
9 | |
6 | |
6 |