Forum Discussion

quikin5's avatar
quikin5
Frequent Visitor
3 years ago

Matrix row totals not working properly

Hi, I have a matrix with year, month (both from a calendar table), and customer as row headers. As for values I have the following measure: 

Lost Customers Amount =
VAR currentCustomers = VALUES(SALES[Customer])
VAR previousMonthDates = PREVIOUSMONTH('DATE'[Date])
VAR previousMonthCustomers = CALCULATETABLE(SALES[Customer]),ALL('DATE'[Date]), previousMonthDates)
VAR LostCustomers= EXCEPT(previousMonthCustomers,currentCustomers)
VAR LastMonthAmount = CALCULATE(SUM(SALES[Sales]), DATEADD('DATE'[Date], -1, MONTH), LostCustomers)
RETURN
    SUMX(LostCustomers, LastMonthAmount)

The measure returns the sales of the customers who purchased the previous month but did not purchase the selected month.

The measure works fine in the matrix at customer level, but fails to aggregate the sum properly at month level.

Any idea would be very appreciated! 

2 Replies