Salesforce Objects
Power BI is a powerful business intelligence tool that allows users to connect to a variety of data sources and create interactive reports and dashboards. One of the most popular data sources for businesses is Salesforce, a customer relationship management (CRM) platform that stores a wealth of sales, marketing, and customer data.
To connect to Salesforce data from inside Power BI, we can use the Power Query M language. M is a functional programming language used by Power Query to transform and manipulate data. In this article, we will explore how to write M code to connect to the Salesforce Objects data source from inside Power BI.
Prerequisites
Before we begin, there are a few prerequisites that you must have in place:
– A Salesforce account with API access enabled
– Power BI Desktop installed on your computer
– A working internet connection
Connecting to the Salesforce Objects Data Source
To connect to the Salesforce Objects data source from inside Power BI, follow these steps:
1. Open Power BI Desktop and select “Get Data” from the Home tab.
2. In the “Get Data” window, select “Salesforce Objects” from the list of available data sources.
3. Enter your Salesforce credentials and click “Connect.”
4. In the “Navigator” window, select the objects you want to import into Power BI.
5. Click “Load” to import the data into Power BI.
By following these steps, you can quickly connect to the Salesforce Objects data source and begin analyzing your data in Power BI. However, there may be times when you need to use M code to connect to the data source instead.
Using M Code to Connect to the Salesforce Objects Data Source
To use M code to connect to the Salesforce Objects data source from inside Power BI, follow these steps:
1. Open Power BI Desktop and select “Blank Query” from the Home tab.
2. In the “View” tab, click “Advanced Editor” to open the M code editor.
3. Paste the following code into the editor:
let
Source = Salesforce.Data(“https://login.salesforce.com/”, [ApiVersion=51]),
Account = Source{[Name=”Account”]}[Data],
#”Filtered Rows” = Table.SelectRows(Account, each ([CreatedDate] > #datetime(2021, 1, 1, 0, 0, 0)))
in
#”Filtered Rows”
4. Replace “Account” with the name of the object you want to import from Salesforce.
5. Replace “2021, 1, 1, 0, 0, 0” with the date you want to filter your data by.
6. Click “Done” to close the M code editor.
7. Click “Load” to import the filtered data into Power BI.
By following these steps, you can use M code to connect to the Salesforce Objects data source and filter your data by date. You can also modify the M code to perform other transformations on the data, such as merging or appending tables.
Conclusion
In this article, we explored how to use M code to connect to the Salesforce Objects data source from inside Power BI. While it is possible to connect to the data source using the graphical interface, using M code allows you to perform more complex transformations on your data. By following the steps outlined in this article, you can quickly and easily connect to the Salesforce Objects data source and begin analyzing your data in Power BI.