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

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.

Reply
MatheusLPS
Helper I
Helper I

How to add schema name to a table and append 25 more tables preserving query folding?

I have a SQL database with multiple schemas:

 

MatheusLPS_0-1624894609733.png

 

Goal: Apeend all "Data" table with Table.Combine and preserve query folding. It is working:

 

MatheusLPS_3-1624895426443.png

 

Problem: After the combine/append, I loose the schema name. So, I do not know where the data comes from.

 

What I am trying: Add the schema name to each of the "Data" tables and after that, Append all.

 

 

Table.AddColumn(Source, "NewTable", each Table.AddColumn([Data], "Schema", each [Schema]))

 

 

Result:

 

MatheusLPS_4-1624895665321.png

 

 

Error: The field 'Schema' from record was not found:

MatheusLPS_2-1624895202460.png

 

Question:

 

How do I add a new column dynamically to my "Data" tables with the name of the schema?

 

Is there another way? Please, I do not want to import each schema individually.

 

Thanks

1 ACCEPTED SOLUTION
MatheusLPS
Helper I
Helper I

Hello. Just solved the problem. I was reading the forum to find another way.

 

Found this: https://community.powerbi.com/t5/Desktop/quot-Expression-Error-We-cannot-apply-field-access-to-the-t...

 

And this: https://ssbi-blog.de/blog/technical-topics-english/the-environment-concept-in-m-for-power-query-and-...

 

Solution: Store the Schema name in a variable by calling a function.

 

 

Table.AddColumn(Source, "NewTable", each Table.AddColumn([Data],"Schema", (X) => let Parameter = [Schema] in Parameter))

 

 

Table 1:

 

MatheusLPS_0-1624910302023.png

Table 2:

MatheusLPS_1-1624910557943.png

Table 32:

MatheusLPS_2-1624910716263.png

 

After Table.Combine all the xxxxx tables, query folding ON!!!! Finally!!!!!!

 

MatheusLPS_3-1624910888131.png

 

Complete code:

 

let
    Fonte = Sql.Database("Server", "Database", [CreateNavigationProperties=false]),
    FilterTables = Table.SelectRows(Fonte, each Text.EndsWith([Name], "NOTIFICATION_CONFIG")),
    AddNewColumn = Table.AddColumn(FilterTables, "NewTable", each Table.AddColumn([Data],"Schema", (X) => let Parameter = [Schema] in Parameter)),
    AppendAll = Table.Combine(AddNewColumn[NewTable])
in
    AppendAll

 

 

 

 

 

 

View solution in original post

1 REPLY 1
MatheusLPS
Helper I
Helper I

Hello. Just solved the problem. I was reading the forum to find another way.

 

Found this: https://community.powerbi.com/t5/Desktop/quot-Expression-Error-We-cannot-apply-field-access-to-the-t...

 

And this: https://ssbi-blog.de/blog/technical-topics-english/the-environment-concept-in-m-for-power-query-and-...

 

Solution: Store the Schema name in a variable by calling a function.

 

 

Table.AddColumn(Source, "NewTable", each Table.AddColumn([Data],"Schema", (X) => let Parameter = [Schema] in Parameter))

 

 

Table 1:

 

MatheusLPS_0-1624910302023.png

Table 2:

MatheusLPS_1-1624910557943.png

Table 32:

MatheusLPS_2-1624910716263.png

 

After Table.Combine all the xxxxx tables, query folding ON!!!! Finally!!!!!!

 

MatheusLPS_3-1624910888131.png

 

Complete code:

 

let
    Fonte = Sql.Database("Server", "Database", [CreateNavigationProperties=false]),
    FilterTables = Table.SelectRows(Fonte, each Text.EndsWith([Name], "NOTIFICATION_CONFIG")),
    AddNewColumn = Table.AddColumn(FilterTables, "NewTable", each Table.AddColumn([Data],"Schema", (X) => let Parameter = [Schema] in Parameter)),
    AppendAll = Table.Combine(AddNewColumn[NewTable])
in
    AppendAll

 

 

 

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors