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
jason435
Helper II
Helper II

Cumulative SUM with filter

I have a budget table with budget amounts for the whole month with date value set to first of the month.

 

I would like to create a cumulative budget to compare against actual. A straight line from bottom left to top right of an area chart that will change based on a date slicer.

 

So I calculate the average budget revenue for one day in the period, then multiply by the number of days to date. 

 

I have the below formula. I know I am messing up which variables are calculated for each day, and which variable is fixed for each calculation. If that makes sense. 

 

 

Sum Budget to date = 
				var maxdate = MAX('Calendar'[Date])
				var mindate = MIN('Calendar'[Date])
				var revenuedays = maxdate - mindate +1
				var budgetdays = FORMAT(EOMONTH(maxdate,0)-mindate+1,0)
				RETURN
				CALCULATE(
					SUM(Budget[Budget Amount])/budgetdays*revenuedays,
					FILTER (
						ALLSELECTED ( 'Calendar'),
						'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
						&& 'Calendar'[Date] >= date(year(TODAY()),1,1)
))

 

1 ACCEPTED SOLUTION

Ok, afte writing my previous post I had a duh moment and figured it out: If anyone has any ideas to make this more efficient please let me know.

 

ToDate Sum Budget = 
			var maxdate = MAX ( 'Calendar'[Date] ) 
			return
			CALCULATE(
			SUM(CRTBudget[Budget Amount]),
			FILTER (
			ALLSELECTED ( 'Calendar'),
			DATEADD('Calendar'[Date],1,MONTH) <= maxdate
			)) 
			+
		CALCULATE(
					sum(CRTBudget[Budget Amount Day])*
					(maxdate - date(year(maxdate),month(maxdate),1)+1),
					FILTER (
						ALLSELECTED ( 'Calendar'),
						month('Calendar'[Date]) = month( maxdate)
						))

 

 

View solution in original post

3 REPLIES 3
jason435
Helper II
Helper II

Been doing some more research on this, I think I have a better grasp of what I need now. I think this is possible with a sumx.

 

ToDate Sum Budget v1 = 
			CALCULATE(
			SUMX(???))),
			FILTER (
			ALLSELECTED ( 'Calendar'),
			'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
			&& 'Calendar'[Date] >= date(year(TODAY()),1,1)
))	

This is for an area chart YTD or MTD chart, depending on the page filter.

 

I have a budget table with month and budget for each month. I added a calculated column with daily budget for each month.

 

For each date, I want to sum: (all budgets up to the end of the previous month) + mtd days * avg daily budget

 

for March 14 = Jan Budget + Feb Budget + 14 *Avg Mar Daily budget

 

for jan 26 = Avg Jan Daily Budget * 26

 

Result should look like the purple line, but with 'cleaner' line.

 

2017-11-22 15_14_40-CRT BI v2 - Power BI Desktop.png

Ok, afte writing my previous post I had a duh moment and figured it out: If anyone has any ideas to make this more efficient please let me know.

 

ToDate Sum Budget = 
			var maxdate = MAX ( 'Calendar'[Date] ) 
			return
			CALCULATE(
			SUM(CRTBudget[Budget Amount]),
			FILTER (
			ALLSELECTED ( 'Calendar'),
			DATEADD('Calendar'[Date],1,MONTH) <= maxdate
			)) 
			+
		CALCULATE(
					sum(CRTBudget[Budget Amount Day])*
					(maxdate - date(year(maxdate),month(maxdate),1)+1),
					FILTER (
						ALLSELECTED ( 'Calendar'),
						month('Calendar'[Date]) = month( maxdate)
						))

 

 

Ashish_Mathur
Super User
Super User

Hi,

 

Share a dataset and show your expecte result.


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

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.