Forum Discussion

userforpowerbi's avatar
userforpowerbi
New Member
4 years ago

Access data in Power BI from a multi-tenant Postgres Database

Hi Folks!

Looking forward to some expert advice for a challenge in my current Power BI project.
I'm trying to connect to Power BI to a Postgres DB which is a multi tenant DB setup (you need to set_context before can see actual data).
Problem is when I write the 2 SQLs ONE to set context and SECOND to access one of the views, power bi runs these 2 queries separately hence different SQL sessions are fired (Please see the FIRST Advance Query below)

 

I have also tried creating a CTE query (Please see the SECOND Advance Query below) but it doest set context at once.

Is there any other way to set database context to access tenant specific data?

Below is the FIRST Advance Query Editor text for your reference

let
   Source = PostgreSQL.Database("xxx.xxx.x.xx:zzzz", "yyyyy", [CreateNavigationProperties=false]),
   #"Run Native Query0"=Value.NativeQuery(
    Source,"select Schema1.Package1.procedureSetTenant(TENANT_ID,USER_ID)",null,[EnableFolding=false]
   ),
   #"Run Native Query"=Value.NativeQuery(
    Source,"select * from Schema2.View1",null,[EnableFolding=true]
   ),
   #"Appended Query" = Table.Combine({#"Run Native Query0", #"Run Native Query"})
in
   #"Appended Query"

 

Below is the SECOND Advance Query Editor text for your reference

let

Source = PostgreSQL.Database("xxx.xxx.x.xx:zzzz", "yyyyy", [CreateNavigationProperties=false]),
#"Run Native Query"=Value.NativeQuery(
Source,"with
a1 as (select -1 as e2b_request_id from hlt_core.pkg_hcore_vpd.p_hcore_set_tenant(10,1)),
a2 as (
select e2b_request_id from a1
union
select e2b_request_id from hlt_capi.hcapi_lso_tracker_eng_dpv )
select e2b_request_id from a2",null,[EnableFolding=true]
)
in
#"Run Native Query"

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi userforpowerbi ,

    Please refer to the blog to see if it helps you.

    Building multi-tenant database context 

     

    Best Regards

    Community Support Team _ Polly

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.