Track your weekly marketing campaign metrics using Dax in Excel — Part 3 — Dynamic KPIs

Up to this point, we’ve transformed our raw data into insightful tables and explored basic DAX functionalities. In this segment, we’re upping the game by allowing users to dynamically select specific weeks and KPIs. This provides the agility to pinpoint metrics, enabling a granular view of our marketing efforts.
Before diving into dynamic calculations, it’s essential to establish a clear structure for our KPIs. By introducing a dedicated reference table for our metrics, we can neatly present the available options to the user and set the stage for our dynamic DAX measures.

Introducing Essential DAX Measures for Dynamic KPIs
With our KPI reference table in place, it’s now time to introduce some pivotal DAX measures that will bridge our user selections to tangible, dynamic outputs. These measures play a crucial role in interpreting user choices and then fetching the relevant metrics from our data model.
The RequiredCalculation Measure:
RequiredCalculation:=IF(HASONEVALUE(Tb_Calculation[Calculation]), VALUES(Tb_Calculation[Calculation]),BLANK())
At its core, the RequiredCalculation
measure checks if a single KPI has been selected using the HASONEVALUE
function. If the user has chosen one of the options (like "Ad Spend" or "Ad Clicks"), it returns the selected value. If not, it defaults to a blank state, ensuring our calculations remain clean and free of potential errors.
The SelectedKPI Measure:
SelectedKPI:=SWITCH( [RequiredCalculation]
, "Ad Spend", ([total_spend])
, "Ad Clicks", ([total_clicks] )
)
Building on the foundation laid by RequiredCalculation
, the SelectedKPI
measure employs the SWITCH
function, a powerful DAX tool. Here, it checks the outcome of RequiredCalculation
— if "Ad Spend" is the chosen KPI, it fetches the total ad spend; if "Ad Clicks" is selected, it retrieves the total clicks. This measure becomes the dynamic heart of our analytics, adjusting real-time based on the user's KPI selection.
Enhancing User Experience with the SelectedKPIWithFormat Measure
SelectedKPIWithFormat:=SWITCH( [RequiredCalculation]
, "Ad Spend", FORMAT([total_spend], "$#,##0.00" )
, "Ad Clicks", FORMAT( [total_clicks], "#,##0" )
)
This measure closely mirrors the functionality of SelectedKPI
By employing the FORMAT
function, we ensure that when the results are displayed in a PivotTable or any other visualization, they are immediately comprehensible, eliminating any guesswork for the end-users.
Updating Our PivotTable with the Dynamic Measure
With the new DAX measures in place, our PivotTable gets an immediate upgrade. Replacing our previous metric with the SelectedKPIWithFormat
measure now provides results that are not only dynamic but also pleasing to the eye, all thanks to our recent format enhancements.
Furthermore, to make KPI selection seamless, a slicer connected to our calculation table has been incorporated. This allows users to effortlessly toggle between “Ad Spend” and “Ad Clicks”, witnessing real-time shifts in the data. A screenshot shared below offers a glimpse into this improved setup:

In Conclusion
The journey we embarked upon with DAX in Excel has proven that even without specialized BI tools, we can achieve dynamic, insightful, and interactive dashboards right within Excel. Leveraging advanced DAX measures, we have transformed a static dataset into a model that offers multiple layers of insights at the click of a button.
As we conclude this segment, it’s important to appreciate the vast possibilities that Power Pivot and DAX have unlocked for us. But remember, this is just the tip of the iceberg. With the foundational knowledge gained here, you’re now equipped to explore even deeper analytics and visualizations in Excel.
Stay tuned for our next segment, where we delve further into advanced DAX functionalities and continue to elevate our data storytelling capabilities!
For those eager to follow along, you can download the dataset from this link. Having the data on hand will provide a practical experience as we navigate through each step together.