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 Meltwater
table with thehbs PR Report
table using thefile_name
column from both tables. It performs a left outer join, meaning all rows from themwr Meltwater
table are retained, and matching rows from thehbs PR Report
table are added.
- The query joins the
- Expanding Merged Data:
- It expands two columns,
Press_release_title
andCampaign.lookupValue
, from thehbs PR Report
table to include them in the result.
- It expands two columns,
- Second Merge:
- The query performs another left outer join, this time between the
Campaign.lookupValue
column from the previous step and theCampaignName
column from theCampaigns
table. This adds related campaign information to the dataset.
- The query performs another left outer join, this time between the
- Expanding Campaigns Data:
- The
CampaignGuid
column from theCampaigns
table is expanded and included in the dataset.
- The
- Adding a Custom Column (
Custom1
):- A new column named
Custom1
is added, where every row gets the value0
.
- A new column named
- Replacing Null Values:
- The query replaces any null values in the
Title
column with the string"-1"
.
- The query replaces any null values in the
- Adding a Conditional Column (
Name
):- A new column named
Name
is added, with values based on a conditional statement:- If the
Title
column has the value"-1"
, the value inName
will be the value from theOpening_Text
column. - Otherwise, it will take the value from the
Title
column.
- 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_Type
becomesSourcesType
Campaign.lookupValue
becomesCampaignId
Document_ID
becomesObjectID
Date
becomesDate_Key
- Adding a Platform Column:
- A new column named
Platform
is added, with the value"PR Coverage"
for all rows.
- Changing Column Types:
- The
Value
column is converted to a numeric data type. - The
Date_Key
column is converted to adate
type.
- Filtering Rows:
- Finally, the query filters the rows, keeping only those where the
CampaignGuid
column 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.