Forum Discussion
Average revenue based on Date selection
HI Guys,
would appreciate some insight o nhow best to set this up, I have a Calander table (DCalander[date]) and a seperate table containing invoices (transactional data[invoice]) related by date.
I have a Date filter in years at the top of the report, the user can select any number of years as an analysis period (2,3,4 years for example).
I have a Measure for Year Selected to return the revenue value during that period
6 Replies
- MattAllington
Community Champion
Your first formula is overly complex. This will work
YS-Revenue = SUM('Transactional data'[invoive])
as for the other 2, assuming your calendar table has a year column and that is what is in your slicer
Revenue Last selected year = CALCULATE(SUM('Transactional data'[invoive]),All(calendar),calendar[year]=max(calendar[year]))
Avg yearly Revenue = averagex(values(calendar[year]),CALCULATE(SUM('Transactional data'[invoive]))
- Gareth_Hunt
Helper II
Hi Matt,
thank you for coming bac kto me on this one,
so I took your example expression and input it into my model, but I get this error
nb replaces BLIV70- invoice revenue
As for the second answer, this would return an average for all years seleected I want to exclude hte last year from the average
appreciate your feedback thanks!
Gareth
- MattAllington
Community Champion
sorry for the error. that's what happens when you write DAX on an ipad
Revenue Last selected year =
CALCULATE (
SUM ( 'Transactional data'[invoice] ),
FILTER ( ALL ( calendar ), calendar[year] = MAX ( calendar[year] ) )
)Note above: ALL(Calendar[Year]) is more efficient than ALL(Calendar) but I don't know if it will work for you given you haven't shared what else you are doing. You should try using that - it if works, it is better.
Avg yearly Revenue =
AVERAGEX (
CALCULATETABLE (
VALUES ( calendar[year] ),
FILTER ( ALL ( calendar[year] ), calendar[year] <> MAX ( calendar[year] ) )
),
CALCULATE ( SUM ( 'Transactional data'[invoice] ) )
)