Purpose
The purpose of these queries is to streamline the integration and transformation of marketing and campaign data from multiple sources into a unified format. These Power Query scripts address various types of campaign-related data—ranging from email campaigns, social media posts, and advertising, to events, page performance, and form submissions.
Process
- Source Selection:
- The query starts by loading data from the table called
mwr Meltwater. - myBMT (bmt-dwh-uks-app-my.azurewebsites.net)
- The query starts by loading data from the table called
- Merging Queries:
- The query joins the
mwr Meltwatertable with thehbs PR Reporttable using thefile_namecolumn from both tables. It performs a left outer join, meaning all rows from themwr Meltwatertable are retained, and matching rows from thehbs PR Reporttable are added.
- The query joins the
- Expanding Merged Data:
- It expands two columns,
Press_release_titleandCampaign.lookupValue, from thehbs PR Reporttable to include them in the result.
- It expands two columns,
- Second Merge:
- The query performs another left outer join, this time between the
Campaign.lookupValuecolumn from the previous step and theCampaignNamecolumn from theCampaignstable. This adds related campaign information to the dataset.
- The query performs another left outer join, this time between the
- Expanding Campaigns Data:
- The
CampaignGuidcolumn from theCampaignstable is expanded and included in the dataset.
- The
- Adding a Custom Column (
Custom1):- A new column named
Custom1is added, where every row gets the value0.
- A new column named
- Replacing Null Values:
- The query replaces any null values in the
Titlecolumn with the string"-1".
- The query replaces any null values in the
- Adding a Conditional Column (
Name):- A new column named
Nameis added, with values based on a conditional statement:- If the
Titlecolumn has the value"-1", the value inNamewill be the value from theOpening_Textcolumn. - Otherwise, it will take the value from the
Titlecolumn.
- If the
- A new column named
- Removing Unnecessary Columns:
- The query removes a large number of columns that are no longer needed, such as
URL,Hashtags,Image,Author_Name, and many others. Only essential columns are kept.
- The query removes a large number of columns that are no longer needed, such as
- Unpivoting Data:
- The table is transformed by unpivoting all columns except
Date,Document_ID,Source_Type,Name,Campaign.lookupValue, andCampaignGuid. This means other columns are converted into two columns: Attribute(which contains the original column names) andValue(which contains the corresponding data).
- The table is transformed by unpivoting all columns except
- Renaming Columns:
- Several columns are renamed for clarity:
Source_TypebecomesSourcesTypeCampaign.lookupValuebecomesCampaignIdDocument_IDbecomesObjectIDDatebecomesDate_Key
- Adding a Platform Column:
- A new column named
Platformis added, with the value"PR Coverage"for all rows.
- Changing Column Types:
- The
Valuecolumn is converted to a numeric data type. - The
Date_Keycolumn is converted to adatetype.
- Filtering Rows:
- Finally, the query filters the rows, keeping only those where the
CampaignGuidcolumn is not null (i.e., it excludes rows with missing campaign data).
- Result Output:
- The transformed data is returned as the output of the query.