Forum Discussion
measure value incorrect when no data present
- 7 years ago
Hi Anonymous,
I have had a look at your code, and you need to rewrite it a little to get what you are looking for. The code you posted:
3 Year Sales = CALCULATE ( SUM ( SalesAgg[Sales] ) + 0, FILTER ( ALL ( 'DATES' ), AND ( 'DATES'[Year] >= SELECTEDVALUE ( 'DATES'[Year] ) - 2, 'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] ) ) ) )calculates, according to the conditions of the FILTER-function that you should sum all values where year is greater than or equal to the year in the current filter context - 2. When you look at the first row of your table, your earliest period is Q2 2017. This means that your code is summing all rows where year greater than or eqaul to 2015.
You also have a condition which says you should only sum rows where the quarter number is the same as the current quarter number. Not sure whether this is intentional or not. So again, looking at your first reporting period Q2 2017, the [3 year sale] is the sum of all Q2 where year is greater than 2015.
I am not entirely sure what you are trying to do, so I can only make an educated guess as to what your measure should look like:3 Year Sales = CALCULATE ( SUM ( SalesAgg[Sales] ) + 0, FILTER ( ALL ( 'DATES' ), 'DATES'[Year] >= SELECTEDVALUE ( 'DATES'[Year] ) - 2 && 'DATES'[Year] <= SELECTEDVALUE ( 'DATES'[Year] ) && 'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] ) ) )
Cheers,
Sturla
Hi Anonymous,
I have had a look at your code, and you need to rewrite it a little to get what you are looking for. The code you posted:
3 Year Sales =
CALCULATE (
SUM ( SalesAgg[Sales] ) + 0,
FILTER (
ALL ( 'DATES' ),
AND (
'DATES'[Year]
>= SELECTEDVALUE ( 'DATES'[Year] ) - 2,
'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] )
)
)
)calculates, according to the conditions of the FILTER-function that you should sum all values where year is greater than or equal to the year in the current filter context - 2. When you look at the first row of your table, your earliest period is Q2 2017. This means that your code is summing all rows where year greater than or eqaul to 2015.
You also have a condition which says you should only sum rows where the quarter number is the same as the current quarter number. Not sure whether this is intentional or not. So again, looking at your first reporting period Q2 2017, the [3 year sale] is the sum of all Q2 where year is greater than 2015.
I am not entirely sure what you are trying to do, so I can only make an educated guess as to what your measure should look like:
3 Year Sales =
CALCULATE (
SUM ( SalesAgg[Sales] ) + 0,
FILTER (
ALL ( 'DATES' ),
'DATES'[Year]
>= SELECTEDVALUE ( 'DATES'[Year] ) - 2
&& 'DATES'[Year] <= SELECTEDVALUE ( 'DATES'[Year] )
&& 'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] )
)
)
Cheers,
Sturla
- Anonymous7 years agoNot applicable
sturlaws Thank you very much.
I dont know how i missed that part. I felt like a stupid for a minute.
Yes, I fixed the Measure and now it's working correctly. we do not want all future years. Only 3 years worth.