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
Anonymous
Not applicable

need help -cumulative sum for each month with no slicer

I am stuck in a situation. 
I have a revenue table connected to the calendar table by a date column. 

On the report page, I shouldn't have a date slicer.

I need to create a line chart, showing two lines, line1 cumulative sum for this month (i.e. from 01.02 to 16.02) and line2 shows cumulative sum for the same period last month ( i.e. 01.01 to 16.01). The x-axis should be Month-day-number (means from 1 to 31). 

 

I made the cumulative sum as follow: 

revenue-CM =
VAR MaxDate= TODAY()-1
VAR StartOfCurrentMonth = EOMONTH(TODAY()-1,-1) + 1
RETURN
CALCULATE(
SUM(revenue[revenue]),
'Calendar'[DateValue]<= MaxDate, 'Calendar'[DateValue]>=StartOfCurrentMonth)


Revenue-LM =
VAR StartOfPreviousMonth = EOMONTH(TODAY(),-2) + 1
VAR EndofPreviousMonth = EOMONTH(TODAY(),-1)
VAR CurrentDay= DAY(TODAY()-1)

RETURN (CALCULATE(SUM(Revenue[Revenue]),'Calendar'[MonthDayNumber]<=CurrentDay,'Calendar'[DateValue] >= StartOfPreviousMonth, 'Calendar'[DateValue]<= EndofPreviousMonth))
 
 
both of them are returning the final correct numbers. But they return the same number for each day.
image.png

 

can anybody help me? 

all the cumulative measures are with ALLSELECTED() function, or with MAX(DATE) , and they all work fine with a date filter (slicer).

1 ACCEPTED SOLUTION

@Anonymous , if you are using date from a date in visual you do not need a slicer, it should work 

 

you can try like

 

MTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , with help from date table-use datesmtd

Revenue

MTD Sales = CALCULATE(SUM(Revenue[Revenue]),DATESMTD('Date'[Date]))

Anonymous
Not applicable

@amitchandak 

Thank you or your answer. 

DATESMTD() works fine when there is a date filet on the page or on the visual. 

 

I need a formula which works without a date slicer. 

and the second point is that, with DATESMTD(), we can not have a cumulative sum from first day of last month to today's day at last month (today is 17.02, so to 17.01)

@Anonymous , if you are using date from a date in visual you do not need a slicer, it should work 

 

you can try like

 

MTD QTY forced=
var _max = today()
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESMTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESMTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALMTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

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.