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
vvcortazar
New Member

Dynamically comparing current totals to last year totals

Hi, I have a table that has data for each month for some years, I need to come up with a formula to add three months and then divided then to the same period of the previous year.

Jun 2016150451  
Jul 2016548105  
Aug 20167120201410576 
Sep 2016181055  
Oct 2016481209  
Nov 2016181940  
Dec 2016246501  
Jan 2017257810  
Feb 2017180248  
Mar 2017293700  
Apr 2017213000  
May 2017241600  
Jun 2017270201  
Jul 2017252900  
Aug 20171527686758690.47914398

 

 

Let me try to explain, I this example I need to sum the values for the period from June to August for 2017 and 2016 and then divide them. 

So far I made a measure that obtains the rolling sum of the three months and another to get the data for the previous year using the SAMEPERIODLASTYEAR formula but I get an error that the formula expects a contiguos selection when the date column is not unique. I can't figure the correct way to do this.

 

For the running total my measure is 

RunningTotal = var minDate= DATE(YEAR(MAX(Dates[Date])),MONTH(max(Dates[Date]))-2,DAY(mAX(Dates[Date])))
return
SUMX(FILTER(ALL('CAGR'),[CAGR_DATE]>= minDate&&[CAGR_DATE]<=MAX([CAGR_DATE])),[CAGR])

 

Any help is greatly appreciated.

1 ACCEPTED SOLUTION

Hi @vvcortazar,

 

From the error message, please check whether Dates[Date] contains continual dates. If not, you need to create a separate calendar table use CALENDAR function, then relate your current table to the new date table.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

 

Here are the calculated field formulas that i wrote

 

Amount1

 

=CALCULATE(SUM(Data[Amount]),DATESYTD('calendar'[Date],"31/5"))

Amount in same period last year

 

=CALCULATE([Amount1],SAMEPERIODLASTYEAR('calendar'[Date]))

Achievement (%)

 

=[Amount1]/[Amount in same period last year]

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

With the second formula I get the same message as before: 

MdxScript(Model) (12, 67) Calculation error in measure 'Data'[Amount in same period last year]: Function 'SAMEPERIODLASTYEAR' expects a contiguous selection when the date column is not unique, has gaps or it contains time

Hi @vvcortazar,

 

From the error message, please check whether Dates[Date] contains continual dates. If not, you need to create a separate calendar table use CALENDAR function, then relate your current table to the new date table.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the reply, I created the Dates table and now everyting works fine. 

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.