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
gmasta1129
Helper III
Helper III

Month End Data_% Change

Hello, 

 

I am trying to calculate the % change month over month (month end/last day of month).  

 

**Please note the run date is first day of month because our data is on a 1 day lag.  Is it possible to create a fomula (calculated column or measure) to fix this? Where it looks at the date in '"Run Date" and pulls the date for the last day of the previous month? I couldnt figure out a formula for that. 

 

 

gmasta1129_1-1644124798778.png

 

The two formula's i used are shown below.  It seems to be working but only for the last row (2/1/2022). The other two rows are 0.00% (see screenshot above).  Not sure what is wrong with my formulas.  

 

If there is an easier way to do this, please let me know. 

 

Utilization - Overall MOM % Chg = IFERROR((sum('daily_report'[Utilization Overall]) - [Utilization - Overall Prev Months])/[Utilization - Overall Prev Months],0)

 

 

 

Utilization - Overall Prev Months =
VAR __PREV_MONTH =
CALCULATE(
sum('daily_report'[Utilization Overall]),
DATEADD(daily_report[Run Date 2], -30, DAY)
) + CALCULATE(
sum('daily_report'[Utilization Overall]),
DATEADD(daily_report[Run Date 2], -31, DAY)
) + CALCULATE(
sum('daily_report'[Utilization Overall]),
DATEADD(daily_report[Run Date 2], -32, DAY)
) + CALCULATE(
sum('daily_report'[Utilization Overall]),
DATEADD(daily_report[Run Date 2], -29, DAY)
)
RETURN
__PREV_MONTH

 

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @gmasta1129 ,

 

I have to admit that I do not fully understand why it's necessary to calculate the MoM change based on the Month's end date.
Nevertheless, my sample data looks like this:

image.png

The I use the below 2 DAX statements to create calculated columns, one returns the month end date of the current month based on Run Date 2 value and the other returns end of month of the previous month.

End Of Month = 
EOMONTH( 'Table'[Run Date 2] , 0 ) 

 

End Of Prev Month = 
EOMONTH( 'Table'[Run Date 2] , -1 ) 

Then my table looks like this:

image.png

Finally, I use the below DAX statement to create a calculated column that returns the MoM change:

MoM change = 
var prevMonthValue = LOOKUPVALUE('Table'[Utilization_Overlall] ,'Table'[End Of Month] , 'Table'[End Of Prev Month] )
return
if( isblank(prevMonthValue )
    , BLANK()
    , ( divide( 'Table'[Utilization_Overlall] , prevMonthValue ) - 1 ) * 100
)

I recommend, reading this article Time patterns – DAX Patterns, the article provides almost everything for date-based calculations, and also explains why using a dedicated calendar table is so important.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
gmasta1129
Helper III
Helper III

I have a slicer on the page which filters it by portfolio code ex: 54321, 12332, 23421 etc.  Does this need to be added to the lookup? And if so, how would that be done? 

Hey @gmasta1129 ,

 

please be aware that caculated columns will be only "calculated" during data refresh and design time.

Here you will find more information about the LOOKUPVALUE function: https://dax.guide/lookupvalue/

 

What it makes more difficult to provide further help is the fact that the data from your original post does not contain a column portfolio code.

 

Provide a Power BI file that contains sample data but still reflects your data model (tables, relationships, calculated columns, and. measures). Upload the file onedrive or dropbox and share the link in this thread.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
gmasta1129
Helper III
Helper III

Hello Tom,

 

Thank you for the quick response.  

I copy and pasted the formula and receive the error message below...

"A table of mulitple values was supplied where a single value was expected." 

 

gmasta1129_0-1644133794157.png

 

Hey @gmasta1129 ,

 

I assume you receive the error because lookupvalue finds more than matching row.
Either you add more than a single search/value pair to the LOOKUPVALUE function or you replace the function using FILTER in combination with an iterator function like SUMX to aggregate the values

 

If you need more help, create a pbix that contains sample data, upload the pbix to onedrive or dropbox and share the link.

If you are using Excel to create the sample data instead of the manual input method, share the xlsx as well.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
TomMartens
Super User
Super User

Hey @gmasta1129 ,

 

I have to admit that I do not fully understand why it's necessary to calculate the MoM change based on the Month's end date.
Nevertheless, my sample data looks like this:

image.png

The I use the below 2 DAX statements to create calculated columns, one returns the month end date of the current month based on Run Date 2 value and the other returns end of month of the previous month.

End Of Month = 
EOMONTH( 'Table'[Run Date 2] , 0 ) 

 

End Of Prev Month = 
EOMONTH( 'Table'[Run Date 2] , -1 ) 

Then my table looks like this:

image.png

Finally, I use the below DAX statement to create a calculated column that returns the MoM change:

MoM change = 
var prevMonthValue = LOOKUPVALUE('Table'[Utilization_Overlall] ,'Table'[End Of Month] , 'Table'[End Of Prev Month] )
return
if( isblank(prevMonthValue )
    , BLANK()
    , ( divide( 'Table'[Utilization_Overlall] , prevMonthValue ) - 1 ) * 100
)

I recommend, reading this article Time patterns – DAX Patterns, the article provides almost everything for date-based calculations, and also explains why using a dedicated calendar table is so important.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.