Salesforce.Reports

D

T

The M Code Behind the Power Query M function Salesforce.Reports

Power Query is a data connection technology that allows users to connect, transform, and manipulate data from various sources within Excel. The M function is a key component of Power Query, which provides a powerful and flexible way to transform data using custom code. In this article, we will take a closer look at the M code behind the Power Query M function Salesforce.Reports, which is used to connect to Salesforce reports within Excel.

Connecting to Salesforce Reports

The first step in using the Salesforce.Reports function is to connect to the Salesforce report that you want to retrieve data from. This can be done by providing the URL of the report to the function. The URL can be obtained by navigating to the report in Salesforce and copying the URL from the address bar.


Source = Salesforce.Reports(“https://.my.salesforce.com/“)


The part of the URL should be replaced with your actual Salesforce domain name, and the part should be replaced with the actual ID of the report that you want to retrieve data from.

Authentication

Before connecting to Salesforce reports, it is important to authenticate with Salesforce by providing your username and password. This can be done using the following code:


Source = Salesforce.Reports(“https://.my.salesforce.com/“, [ApiVersion = 28, Username = ““, Password = ““])


The ApiVersion parameter is used to specify the version of the Salesforce API that you want to use. The default version is 28, but you can specify a different version if needed.

Transforming Data

Once you have connected to the Salesforce report and authenticated with Salesforce, you can use the M code to transform the data in various ways. For example, you can filter the data, sort the data, or remove unnecessary columns. The following code shows how to filter the data to only include records where the Account Type is "Customer".


FilteredRows = Table.SelectRows(Source, each ([Account Type] = “Customer”))


The Table.SelectRows function is used to filter the rows based on a specified condition. In this case, the condition is that the value in the Account Type column must be "Customer".

Aggregating Data

Another common task when working with data is to aggregate the data to calculate summary statistics such as counts, sums, or averages. The following code shows how to group the data by the Account Type column and calculate the count of records in each group.


GroupedRows = Table.Group(Source, {“Account Type”}, {{“Count”, each Table.RowCount(_), type number}})


The Table.Group function is used to group the rows based on one or more columns. In this case, we are grouping by the Account Type column. The second parameter specifies the list of aggregation operations to apply to each group. In this case, we are calculating the count of records in each group using the Table.RowCount function.

In conclusion, the Power Query M function Salesforce.Reports provides a powerful and flexible way to connect to Salesforce reports within Excel. The M code allows users to transform and manipulate the data in various ways, making it easy to generate custom reports and gain valuable insights into business performance. By understanding the M code behind the Salesforce.Reports function, users can take full advantage of the capabilities of Power Query and Salesforce to streamline their data analysis and reporting workflows.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)