0
0
Power-biHow-ToBeginner ยท 3 min read

How to Create Month-over-Month (MoM) Calculation in Power BI Using DAX

To create a Month-over-Month (MoM) calculation in Power BI, use the CALCULATE function combined with DATEADD to shift the date context by one month. A common DAX formula is: MoM Growth = DIVIDE(SUM(Sales[Amount]) - CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH)), CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH))), which calculates the percentage change from the previous month.
๐Ÿ“

Syntax

The basic syntax for a Month-over-Month (MoM) calculation in DAX uses these functions:

  • CALCULATE(): Changes the filter context to calculate values for a specific period.
  • DATEADD(): Shifts the date by a specified number of intervals (e.g., months).
  • SUM(): Aggregates the numeric column, like sales amount.
  • DIVIDE(): Safely divides two numbers and handles division by zero.

Example syntax:

DAX
MoM Growth = DIVIDE(
    SUM(Sales[Amount]) - CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH)),
    CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH))
)
๐Ÿ’ป

Example

This example calculates the Month-over-Month growth percentage for sales amount. It compares the current month's sales to the previous month's sales and shows the growth rate.

DAX
MoM Growth = DIVIDE(
    SUM(Sales[Amount]) - CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH)),
    CALCULATE(SUM(Sales[Amount]), DATEADD(Calendar[Date], -1, MONTH))
) * 100
Output
If current month sales = 1200 and previous month sales = 1000, MoM Growth = ((1200 - 1000) / 1000) * 100 = 20%
โš ๏ธ

Common Pitfalls

Common mistakes when creating MoM calculations include:

  • Not having a proper continuous date table marked as a date table in Power BI.
  • Using PREVIOUSMONTH() without a proper date context, which can return blank results.
  • Forgetting to multiply by 100 to convert the ratio to a percentage.
  • Not handling division by zero, which DIVIDE() safely manages.

Wrong approach example:

DAX
MoM Growth Wrong = (SUM(Sales[Amount]) - SUM(Sales[Amount])) / SUM(Sales[Amount])
Output
Always returns 0 because it compares the same value without shifting date context.
๐Ÿ“Š

Quick Reference

FunctionPurposeExample Usage
CALCULATE()Changes filter contextCALCULATE(SUM(Sales[Amount]), DATEADD(...))
DATEADD()Shifts dates by intervalDATEADD(Calendar[Date], -1, MONTH)
SUM()Aggregates valuesSUM(Sales[Amount])
DIVIDE()Safe divisionDIVIDE(numerator, denominator)
โœ…

Key Takeaways

Use CALCULATE with DATEADD to shift the date context by one month for MoM calculations.
Always use DIVIDE to avoid errors from division by zero.
Ensure you have a continuous date table marked as a date table in Power BI.
Multiply the result by 100 to express MoM growth as a percentage.
Avoid comparing values without shifting the date context, which leads to incorrect results.