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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
cheid_4838
Helper IV
Helper IV

Connecting to 2 Servers

I have SQL logic (below) that connects to two different servers (in bold) and databases.  I know how to connect to one server in Power BI, but is there anyway to utilize this logic in Power BI when more than one server is being referenced in the logic?  Thanks for your help.

 

--VENTURE TRANSPORT SERVER
SELECT
ltrim(rtrim(r.CUSTNMBR)) as CUSTNMBR
, c.[Customer Name]
, co.cmp_othertype2 as CSR
, ISNULL(lf.[name], 'UNKNOWN') as [CSR Name]
, c.[Average Days To Pay - Year]
, lf2.edicode as Terms
, ltrim(rtrim(r.DOCNUMBR)) as DocNum
, ISNULL(ih.ivh_xferdate,POSTDATE) as PostDate
, r.RMDTYPAL AS [Doc Type]
, DATEDIFF(DAY, ih.ivh_xferdate, GETDATE()) as Age
, (DATEDIFF(DAY, ih.ivh_xferdate, GETDATE())) - lf2.edicode as AgeOverTerms
, case when r.rmdtypal = 7 then r.curtrxam * -1 else r.curtrxam end as TotalDue
, case when ((DATEDIFF(DAY, ih.ivh_xferdate, GETDATE())) - lf2.edicode) > 0
then case when r.rmdtypal = 7 then r.curtrxam * -1 else r.curtrxam end
else 0 end as TotalPastTerms
, case when ((DATEDIFF(DAY, ih.ivh_xferdate, GETDATE())) - lf2.edicode) > 0
then 1 else 0 end as TermCount
, 'VL' as Company
--, (select top 1 ce.contact_name from TMWSuite_Transcorr.dbo.companyemail ce where ce.cmp_id = r.CUSTNMBR and ce.type = 'AP' and ce.ce_phone1 is not null) as ContactName
, contact_info.[Contact Name] AS [ContactName]
--, isnull((select top 1 ce.ce_phone1 from TMWSuite_Transcorr.dbo.companyemail ce where ce.cmp_id = r.CUSTNMBR and ce.type = 'AP' and ce.ce_phone1 is not null),co.cmp_primaryphone) as ContactPhone
, ISNULL(contact_info.[Contact Phone], co.cmp_primaryphone) AS [ContactPhone]
--, (select top 1 ce.ce_phone1_ext from TMWSuite_Transcorr.dbo.companyemail ce where ce.cmp_id = r.CUSTNMBR and ce.type = 'AP' and ce.ce_phone1 is not null) as ContactExt
, contact_info.[Contact Ext] AS [ContactExt]
--, (select top 1 ce.email_address from TMWSuite_Transcorr.dbo.companyemail ce where ce.cmp_id = r.CUSTNMBR and ce.type = 'AP' and ce.ce_phone1 is not null) as ContactEmail
, contact_info.[Contact Email] AS [ContactEmail]
--, (select top 1 n.not_text_large from TMWSuite_Transcorr.dbo.notes n where n.nre_tablekey = r.DOCNUMBR and n.not_type = 'COLL' and n.ntb_table = 'invoiceheader' order by n.last_updatedatetime desc) as InvoiceNote
, notes_info.[Note Text] AS [InvoiceNote]
, case when r.rmdtypal = 7 then r.ORTRXAMT * -1 else r.ORTRXAMT end as Original
, ih.ivh_ref_number as RefNum
, ih.ord_hdrnumber as OrderNum
, cn2.noteindx as NoteID
, cn2.Date1
, cn2.Action_Promised
, cn2.Action_Assigned_To
, cnn.txtfield as Note
, cn2.CNTCPRSN as Contact
--, (select top 1 cn3.Note_Display_String from [VLCCI-GPSQL16].VNLO.dbo.cn00100 cn3 left join[VLCCI-GPSQL16].VNLO.dbo.cn00100 cn4 on cn4.noteindx = cn3.noteindx where cn4.noteindx is null and cn3.CUSTNMBR = c.[Customer Number] order by cn3.Date1 desc) as BillToNote
, billto_notes.[Note Display String] AS [BillToNote]
, co.cmp_creditlimit as CreditLimit
, ltrim(rtrim(mgr.CRDTMGR)) as CRDTMGR
, case when co.cmp_revtype1 in ('JOYE','JYTS','TRCR','VNLO') then 'Transport'
when co.cmp_revtype1 in ('TGS','VGS') then 'Solutions'
when co.cmp_revtype1 in ('VRWD','VWD') then 'Warehouse'
else 'UNK' end as RevType1
--, (SELECT MAX(ref_number) FROM ReferenceNumber r WHERE r.ord_hdrnumber = ih.ord_hdrnumber AND r.ref_table = 'orderheader' and ref_sequence = 1) as Ref1
, first_ref.[Ref Number] AS [Ref1]
--, (SELECT MAX(ref_number) FROM ReferenceNumber r WHERE r.ord_hdrnumber = ih.ord_hdrnumber AND r.ref_table = 'orderheader' and ref_sequence = 2) as Ref2
, second_ref.[Ref Number] AS [Ref2]
--, (SELECT MAX(ref_number) FROM ReferenceNumber r WHERE r.ord_hdrnumber = ih.ord_hdrnumber AND r.ref_table = 'orderheader' and ref_sequence = 3) as Ref3
, third_ref.[Ref Number] AS [Ref3]
--, (SELECT MAX(ref_number) FROM ReferenceNumber r WHERE r.ord_hdrnumber = ih.ord_hdrnumber AND r.ref_table = 'orderheader' and ref_sequence = 4) as Ref4
, fourth_ref.[Ref Number] AS [Ref4]
--, (SELECT MAX(ref_number) FROM ReferenceNumber r WHERE r.ord_hdrnumber = ih.ord_hdrnumber AND r.ref_table = 'orderheader' and ref_sequence = 5) as Ref5
, fifth_ref.[Ref Number] AS [Ref5]
, lf3.name as Division
, order_note.[Note Text] AS [OrderNote]
INTO #TEMP

1 ACCEPTED SOLUTION
Wilson_
Memorable Member
Memorable Member

cheid_4838,

 

Without looking at the query, it sounds like you could create this query as a stored procedure or a view in SQL server, then reference it in Power Query.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
Wilson_
Memorable Member
Memorable Member

cheid_4838,

 

Without looking at the query, it sounds like you could create this query as a stored procedure or a view in SQL server, then reference it in Power Query.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.