How to use Azure Functions and SharePoint CSOM for data transformation


In the previous post I showed how to create Azure Function and interact with SharePoint Online using SharePoint CSOM and Access Token received from Azure Active Directory using ADAL.NET. In this post I will continue to work with Azure Functions and will create a function that actually has some business logic and can be used in real-life scenarios.


You need to have Azure Subscription and Office 365 Dev Tenant. Refer to the previous posts in this category to get started with Azure Active Directory apps.


More and more customers migrated their on-prem infrastructure to Azure, some of them want to implement various customizations. In this particular case our goal is to display a stacked bar chart on the page based on data from a list. Loading data from Source List and making transformation on Client-Side is usually a bad idea. A list can contain thousands of items, so it may take minutes or even hours to load required information from list and prepare it for visualization. In order to address this concern it is possible to prepare data for visualization using custom code on server-side. There are many ways to do this, but the best possible option should follow the following pattern:

  1. React to changes in the source list
  2. Invoke custom code on server-side to transform data from the source list
  3. Save transformed data to the destination list
  4. Display data on a dashboard

In this particular post I am going to implement Azure Function that will do the data transformation. I am going to use this function latter in Azure Logic App. The approach is very similar to what I have done in the previous post, just create another Azure Function and call it TransformListData:

This function will load data from Source List, calculate number if items with the same title by week in a year and save results to Destination List. For example, if you add the following items to the Source List:

you should have the following items as a results in Destination List:

The next step is to add some code that will do the job, I am not going to put the code here, just go to GitHub and copy-paste everything you need. Make sure you uploaded a valid certificate and updated all required properties.

The function can be tested like this:


In this post I described how to implement a simple data transformation using Azure Functions. In the next post I am going to show how to integrate this function with Azure Logic Apps.