Forum Discussion
Connecting to SQL Server while keeping relationships active
- 2 years ago
Austen229022 I would recommend creating a view in the SQL putting the logic there and then using that view in Power BI to pull the data. If tomorrow there is a need to change the logic, you can do it in the view, and no need to touch Power BI.
Yes, you can import live data from SQL into Power BI while keeping the relationships from SQL Manager. Here are the steps you can follow:
1. Go to the `Home` tab of Power BI and click on `Get Data` drop down and further click on `SQL Server`³.
2. A new SQL Server database window will open. Provide server name and database name³.
3. Select `DirectQuery` as data connectivity mode³.
4. Expand `Advanced Option` and paste your query in `SQL statement`³.
This will allow you to import live data directly from the SQL query into Power BI³.
As for the relationships, it's recommended to create views in your SQL database instead of importing tables directly². This creates an indirection layer that simplifies the change management of the database structure². When you import these views into Power BI, it should maintain the relationships defined in SQL.
However, you might still need to define some relationships within Power BI depending on your specific use case and how you plan to use the data within your reports.
Remember, it's always a good practice to only include the columns that are useful and will be used in the Power BI data model when creating your views². This can help improve performance and usability.
I hope this helps! Let me know if you have any other questions.