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
Anonymous
Not applicable

Help with DW Schema queries

I'm working with multiple servers which have the same database, so I have to combine them. Sometimes they stop working, so I set parametes (ACT_Source...) to indicate if they are online or not.

The first query is currently working. I would like to change the second query (which has a different pattern) to have the same 

I have two types of query and I would like to let them at the same patern.

 

let
    fxConnection =
        (server as text) as table =>
            Table.AddColumn(
                Sql.Database(server, Database, [Query="SELECT... "]),
                "Server",
                each server
            ),
    #"CombinedTables" =
        Table.Combine(List.RemoveNulls(
            {
                if ACT_SourceARA = 1 then
                    fxConnection(ARA)
                else
                    null,
                if ACT_SourceGOI = 1 then
                    fxConnection(GOI)
                else
                    null,
                if ACT_SourceIBI = 1 then
                    fxConnection(IBI)
                else
                    null
            })
        )
in
    #"CombinedTables"

 

This is second query:

 

let
    Source = Sql.Database(server, Database),
    DW_DEClass = Source{[Schema="DW",Item="DEClass"]}[Data]
in
    DW_DEClass

 

I think it should looks like the query bellow. I tried add lines 2 and 3 from second query into the first query, but I don't know exactly what should be changed to make this work.

 

let
    fxConnection =
        (server as text) as table =>
            Table.AddColumn(

              ( Source = Sql.Database(server, Database),
                DW_DEClass = Source{[Schema="DW",Item="DEClass"]}[Data] )

                "Server",
                each server
            ),
    #"CombinedTables" =
        Table.Combine(List.RemoveNulls(
            {
                if ACT_SourceARA = 1 then
                    fxConnection(ARA)
                else
                    null,
                if ACT_SourceGOI = 1 then
                    fxConnection(GOI)
                else
                    null,
                if ACT_SourceIBI = 1 then
                    fxConnection(IBI)
                else
                    null
            })
        )
in
    #"CombinedTables"​

 

I appreciate any help!

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this (I can't see you passing Database here. You might need to replace Database with something like "Database" here depending upon your database name)

 

let
    fxConnection =
        (server as text) as table =>
            Table.AddColumn(
                Sql.Database(server, Database){[Schema="DW",Item="DEClass"]}[Data],
                "Server",
                each server
            ),
    #"CombinedTables" =
        Table.Combine(List.RemoveNulls(
            {
                if ACT_SourceARA = 1 then
                    fxConnection(ARA)
                else
                    null,
                if ACT_SourceGOI = 1 then
                    fxConnection(GOI)
                else
                    null,
                if ACT_SourceIBI = 1 then
                    fxConnection(IBI)
                else
                    null
            })
        )
in
    #"CombinedTables"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Use this (I can't see you passing Database here. You might need to replace Database with something like "Database" here depending upon your database name)

 

let
    fxConnection =
        (server as text) as table =>
            Table.AddColumn(
                Sql.Database(server, Database){[Schema="DW",Item="DEClass"]}[Data],
                "Server",
                each server
            ),
    #"CombinedTables" =
        Table.Combine(List.RemoveNulls(
            {
                if ACT_SourceARA = 1 then
                    fxConnection(ARA)
                else
                    null,
                if ACT_SourceGOI = 1 then
                    fxConnection(GOI)
                else
                    null,
                if ACT_SourceIBI = 1 then
                    fxConnection(IBI)
                else
                    null
            })
        )
in
    #"CombinedTables"

 

Anonymous
Not applicable

Thank you again @Vijay_A_Verma!!

You have saved me twice today 😄

 

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
Top Kudoed Authors