Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
norbi
Helper I
Helper I

Measure to calculate Monthly Growth

Hi,

 

This is my first post and am very new to DAX functions. What I would like to achieve is to sum the prior months data and the current months data to calculate the percentage growth on the totals. The table however only illustrates the numbers for different items and needs to be SUM up then calculated. Below you will find a example table:

periodbilled
01 January 20161
01 January 20161
01 January 20161
01 January 20161
01 January 20161
01 February 20161
01 February 20161
01 February 20161
01 February 20161
01 February 20161
01 February 20161
01 March 20161
01 March 20161
01 March 20161
01 March 20161
01 March 20161
01 March 20161
01 March 20161
01 April 20161
01 April 20161
01 April 20161
01 May 20161
01 May 20161
01 May 20161
01 May 20161
01 June 20161
01 June 20161

 

Desired result:

Jan5 
Feb620.00%
Mar716.67%
Apr3-57.14%
May433.33%
Jun2-50.00%

 

I have tried the following without success:

test_2 = (CALCULATE(SUM('test.txt'[billed]), PREVIOUSMONTH('test.txt'[period])) - sum('test.txt'[billed])) /CALCULATE(SUM('test.txt'[billed]), PREVIOUSMONTH('test.txt'[period]))

 

 

6 REPLIES 6
Phil_Seamark
Employee
Employee

Hi @norbi and welcome to the community

 

Please give this calculated measure a crack.  Then add it to a Grid along with your two columns

 

Measure = 
Var PrevMonth = CALCULATE(SUM('Table'[billed]),PARALLELPERIOD('Table'[period],-1,MONTH))
Var ThisMonth = CALCULATE(SUM('Table'[billed]))
return DIVIDE((ThisMonth - PrevMonth),PrevMonth)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you @Phil_Seamark I have tried the formula however it looks like the calculation is only on the total:

Capture.JPG

 

I would like to achieve the measure for every month on month percentage.

 

Hi @norbi

 

I double checked and it definitely works for me.

 

Please make sure your Period column is set to the DATE datatype, and your Billed is a numeric datatype. I also format the Measure as a percentage.

 

period.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@norbi

Note that Phil uses a Date while you use a Date Hierarchy,

If you want to use a Hierarchy build a Calendar Table

A generic can be easily built by clicking New Table and typing Calendar Table = CALENDARAUTO( )

then relate the 2 date columns and use the Calendar Table [Date] in the Table/Matrix

then you can also write therse simple Measures to do the same

Total Billed = SUM ( 'Table'[billed] )

Total Bill PM = CALCULATE ( SUM ( 'Table'[billed] ), PREVIOUSMONTH ( 'Calendar Table'[Date] ) )

% Change = DIVIDE ( [Total Billed] - [Total Bill PM], [Total Bill PM], 0 )

MoM Change = [Total Billed] - [Total Bill PM]

And the result...

% Change MoM.png

Hope this helps! Smiley Happy

 

EDIT: You can still use the Measure from above but reference the Calendar date again

Measure =
VAR PrevMonth =
    CALCULATE (
        SUM ( 'Table'[billed] ),
        PARALLELPERIOD ( 'Calendar Table'[Date], -1, MONTH )
    )
VAR ThisMonth =
    CALCULATE ( SUM ( 'Table'[billed] ) )
RETURN
    DIVIDE ( ( ThisMonth - PrevMonth ), PrevMonth )

% Change MoM2.png 

@Seanand @Phil_Seamark,thank you very much for the definition of these Measures. They will most probably work, I am however still struggling with my date format and getting this corrected. For the Calendar Table I get the following error: The optional argument of CALENDARAUTO function must evaluate to a constant value.

Hi @norbi,

 

Could you please provide you formula that use CALENDARAUTO function? This function returns a table with a single column named “Date” that contains a contiguous set of dates. The range of dates is calculated automatically based on data in the model.
https://msdn.microsoft.com/en-us/library/dn802534.aspx

 

Regards,

Charlie Liao

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.