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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Azhar_
New Member

How to replicate given sql logic in powerbi..... (Migrating from SSRS to Powerbi)

Hi all,
We are migrating SSRS reports to powerbi. I have this specific query on which i have spent a lot of time replicating it in powerbi.

SELECT comp_CompanyID FROM vPRBBOSCompanyList

WHERE comp_CompanyID IN

(SELECT CASE WHEN prcr_LeftCompanyID=@CompanyId THEN prcr_RightCompanyID ELSE prcr_LeftCompanyID END As CompanyID

FROM PRCompanyRelationship WITH (NOLOCK)

WHERE (prcr_LeftCompanyID = u@CompanyId OR prcr_RightCompanyID=@CompanyId)

AND prcr_Type IN (27, 28, 29)

AND prcr_Active = 'Y'

AND prcr_Deleted IS NULL)

AND comp_PRListingStatus IN ('L', 'H', 'LUV')

AND LocalSourceStateID IS NULL

OR LocalSourceStateID IN (SELECT DISTINCT prlsr_StateID FROM PRLocalSourceRegion WITH (NOLOCK) WHERE prlsr_ServiceCode IN ('LSSLIC'))

before jumping to replicate all the logic in powerbi, I am trying just this part to be executed first

SELECT comp_CompanyID FROM vPRBBOSCompanyList

WHERE comp_CompanyID IN

(SELECT CASE WHEN prcr_LeftCompanyID=@CompanyId THEN prcr_RightCompanyID ELSE prcr_LeftCompanyID END As CompanyID

FROM PRCompanyRelationship WITH (NOLOCK)


I tried creating a calculated column in the PRCompanyRelationship table. But i found that calculated columns are not dynamic paramter selections wont change the values of the calculated column.

Tried creating a measure but issue is we cannot create measures using columns they have to be aggregated in comparision

Only solution i can think of now is to write custom sql. Using power query parameter .

Can anybody give me a better soloution if it exist??

Thanks.

1 REPLY 1
rajendraongole1
Super User
Super User

Hi @Azhar_  - Converting complex SQL logic like this into Power BI can be challenging , can you try the below approach as mentioned 

Instead of calculated columns, use measures for dynamic filtering based on slicer or parameter values.

Create a new table in Power BI to represent the @CompanyId parameter

CompanyParameter = GENERATESERIES(1, 1000, 1) -- Replace 1-1000 with valid CompanyIDs

Implement the CASE Logic in a Measure: Use DAX to replicate the CASE logic:

 

SelectedCompany =
IF(
SELECTEDVALUE(PRCompanyRelationship[prcr_LeftCompanyID]) = SELECTEDVALUE(CompanyParameter[Value]),
PRCompanyRelationship[prcr_RightCompanyID],
PRCompanyRelationship[prcr_LeftCompanyID]
)

 

Filter the Data for use the measure to filter the vPRBBOSCompanyList table:

 

IsCompanyValid =
IF(
vPRBBOSCompanyList[comp_CompanyID] IN VALUES(SelectedCompany),
1,
0
)

 

Use the IsCompanyValid measure to filter your visuals or tables in Power BI. I hope this will helps you. try the above approach. 

 





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

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.