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.
Hi everyone,
I am trying to access some tables via their names as text using the #shared environment. Assuming for example I have the following two queries (called table1/table2 respectively):
let
tab1 = Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]})
in
tab1
let
tab2 = Table.FromRecords({[CustomerID = 4, Name = "Lisa", Phone = "576-5767"]})
in
tab2
Now I want to acces them in another query like one of the following:
let
first_table = Expression.Evaluate("table1", #shared)
in
first_table
let
first_table = Expression.Evaluate("table1", #shared),
sec_table = Expression.Evaluate("table2", #shared),
res = Table.Combine({first_table, sec_table})
in
res
In preview it works just fine. However, when I am trying to apply the changes, I am getting the following error message when activating the first query:
And this one when activating the second query:
I have also tried to use other methods to access the tables like Record.Field() or to use #sections[Section1] instead of #shared as an environment. Unfortunately, it always works in preview, but throws the respective error message when I am trying to apply the changes. The first error message seems to appear when I am only accessing one table, the second one when I am accessing multiple tables.
Would be great if you could help me out.
Solved! Go to Solution.
@leinad Maybe try something like this:
let
Source = #shared,
#"Converted to Table" = Record.ToTable(Source),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each if Type.Is(Value.Type([Value]), Table.Type) then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"})
in
#"Removed Columns"
@leinad I don't understand why you are using #shared here. There is no reason to do so. Just write your last two queries like this:
let
first_table = table1
in
first_table
let
first_table = table1,
sec_table = table2,
res = Table.Combine({first_table, sec_table})
in
res
@Greg_DecklerThanks for your response. In this case i agree. However, this is just some dummy data to replicate the error. I just wanted to understand why the error messages occur.
The actual usecase is using a function to generate all the names of the tables which are to be combined and depends on a parameter for the number of tables. I hope that makes it a little bit clearer.
@leinad Maybe try something like this:
let
Source = #shared,
#"Converted to Table" = Record.ToTable(Source),
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each if Type.Is(Value.Type([Value]), Table.Type) then 1 else 0),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"})
in
#"Removed Columns"
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
97 | |
75 | |
65 | |
53 |
User | Count |
---|---|
144 | |
103 | |
98 | |
85 | |
64 |