Forum Discussion
Anonymous
7 years agoNot applicable
Sum all values per row until limit is reached with multiple criteria
Hi All, This problem really is a beast and has me stuck so let me give some background first... - Data relates to SAAS sales contracts that can be for any number of months but that are usually <...
sturlaws
Resident Rockstar
7 years agoGood explanation, still tricky to get it right.
I have not been able to solve this using a measure only, perhaps someone else want to give it a go.
I have made a solution using calculated columns, but this allows for less filtering oportunies than pure measure solution would. Essentially, I calculate revenue pr day for each line, and then find the number of days which are within 12 months/365 days from the latest [Contract end date] in each grouping of [Account ID] and [Product category].
Number of days =
VAR LastEndDate =
CALCULATE (
MAX ( data[Contract End Date] );
FILTER (
ALL ( data );
data[Account ID] = EARLIER ( data[Account ID] )
&& data[Product Category] = EARLIER ( data[Product Category] )
)
)
VAR LastEndDatePrevYear =
DATE ( YEAR ( LastEndDate ) - 1; MONTH ( LastEndDate ); DAY ( LastEndDate ) )
RETURN
SWITCH (
TRUE ();
LastEndDatePrevYear < data[Contract End Date]
&& data[Contract Start Date] < LastEndDatePrevYear; DATEDIFF ( LastEndDatePrevYear; data[Contract End Date]; DAY );
LastEndDatePrevYear < data[Contract End Date]
&& data[Contract Start Date] >= LastEndDatePrevYear; DATEDIFF ( data[Contract Start Date]; data[Contract End Date]; DAY )
)[Revenue pr day] =
DIVIDE (
data[Revenue];
DATEDIFF ( data[Contract Start Date]; data[Contract End Date]; DAY )
)and the measure can then be written as
Revenue last 12 months =
CALCULATE (
SUMX ( data; data[Revenue pr day] * data[Number of days] );
FILTER (
ALL ( data );
data[Account ID] = MAX ( data[Account ID] )
&& data[Product Category] = MAX ( data[Product Category] )
)
)Anonymous
7 years agoNot applicable
Thanks for your help! This is close but it is still off by $15,897.21. Please let me know if you (or anyone else) has any ideas.