Forum Discussion
cumulative by group
Hi,
I'm trying to do a cumulative sum by group. I've tried different solutions but none seems to work.
I have a table with millions of entries of booking made and they all are grouped by channel group
I was able to create a cumulative sum for the number of nights as in above picture.
The main problem I get is that it does not sum indevidualy per group when all groups are selected. It groups the nights and shows the same value for all.
this is how I'm calculating the cumulative sum
cumulative nights =
CALCULATE([nr_nights total for group],
FILTER(ALLSELECTED('gc_reports bookings'),
'gc_reports bookings'[book_date].[Date]<= MAX ('gc_reports bookings'[book_date].[Date])))The nr nights total for group is a quick mesure like this
nr_nights total for group =
CALCULATE(
SUM('gc_reports bookings'[nr_nights]),
ALLSELECTED('gc_reports channel_groups'[group])
)
Once you select a specific group, all works.
Sorry if this is a dumb question but what am I doing wrong here?
JoaoTrindade here is the measure
cumulative nights = CALCULATE( [total nights], FILTER( ALLSELECTED('gc_reports bookings'[book_date].[Date]), 'gc_reports bookings'[book_date].[Date] <= MAX ('gc_reports bookings'[book_date].[Date]) ) )also I noticed there is lot of both direction cross filter in your model whcih is a bad idea. anyhow that is seperate topic.
15 Replies
- parry2k
Super User
JoaoTrindade not sure if you need allselected in this measure
nr_nights total for group = SUM('gc_reports bookings'[nr_nights])- JoaoTrindadeFrequent Visitor
that filed is a Quick Mesure of total of nights grouped by channel Group. That is the code that comes out of the quick mesure .
- parry2k
Super User
JoaoTrindade did you changed it as I suggested?