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
Fyouri
Frequent Visitor

Problem with running total

I have a list where i keep track of the total number of hours worked in a company per month. I need to get a sum of the last 12 months  on each row. This is what i would want:

 

Date              Total Hours               Cumulated hours

1/1/2014                  5000                                   5000

1/2/2014                  6000                                 11000

..

1/12/2014               8000                                185000 (total of 1/1/2014 till 1/12/2014)

1/1/2015                 7000                                187000 (total of 1/2/2014 till 1/1/2015)

 

I don't really know if I should do this in a column or a Measure. This is what i have so far: Calculate(Sum('Table'[Total Hours]),DATEADD('Table'[Date],-1,YEAR)<'Table'[Date])). But this is not working. Can someone push me a bit in the right direction please?

 

1 ACCEPTED SOLUTION
sdjensen
Solution Sage
Solution Sage

You could try something like this:

 

CALCULATE(
	SUM( 'Table'[Total Hours] ),
	DATESBETWEEN(
		'DateTable'[Date],
		NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'DateTable'[Date]) ) ),
		LASTDATE ( 'DateTable'[Date] )
	)
)
/sdjensen

View solution in original post

5 REPLIES 5
sdjensen
Solution Sage
Solution Sage

You could try something like this:

 

CALCULATE(
	SUM( 'Table'[Total Hours] ),
	DATESBETWEEN(
		'DateTable'[Date],
		NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'DateTable'[Date]) ) ),
		LASTDATE ( 'DateTable'[Date] )
	)
)
/sdjensen

Sdjensen,

 

I tried this but this gives me just the same value as the column total hours.

Do you have a seperate table with all the dates from the first date in your data to the last and made a relationship between these 2 tables?

/sdjensen

Thanks Sdjensen,

 

I forgot to make a connection between the 2 tables. It works now.

CheenuSing
Community Champion
Community Champion

Hi 

Try this 

Last6SalesNew:=IF(ISBLANK(sum(SalesData[SalesAmount])),BLANK(),
CALCULATE(sum(SalesData[SalesAmount]),
DATESBETWEEN(
Calendar[FullDate],
FIRSTDATE(PARALLELPERIOD(Calendar[FullDate], -6, MONTH)),
LASTDATE(PARALLELPERIOD(Calendar[FullDate], -1, MONTH))
), ALL(Calendar) ))

 

This gives me the sales for the previous six months from current month displayed in the pivot table or charts.

Replace the formulas with the columns in your data model.

This assumes a date table called as Calendar and is linked to the SalesData date field.

 

Best 

Cheenusing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

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.