Forum Discussion
Computing Year on Year Sales Growth based on dynamic date range selection
- 5 years ago
Hi sd89 ,
The previous year value shows blank could be caused by there is no data about 2018 year vallue when you choose 2019.
In addition, we'd better to have a continous date column when using Time-intelligence function like datesbetween, sampleperiodlastyear etc.
You can try to calculate previous year value like this:
previous = VAR _min = CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) ) VAR _max = CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) ) RETURN CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( ALL ( 'Table' ), 'Table'[Date] >= DATE ( YEAR ( _min ) - 1, MONTH ( _min ), DAY ( _min ) ) && 'Table'[Date] <= DATE ( YEAR ( _max ) - 1, MONTH ( _max ), DAY ( _max ) ) ) )Attached a sample file in the below, hopes to help you.
Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi sd89 ,
The previous year value shows blank could be caused by there is no data about 2018 year vallue when you choose 2019.
In addition, we'd better to have a continous date column when using Time-intelligence function like datesbetween, sampleperiodlastyear etc.
You can try to calculate previous year value like this:
previous =
VAR _min =
CALCULATE ( MIN ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
VAR _max =
CALCULATE ( MAX ( 'Table'[Date] ), ALLSELECTED ( 'Table' ) )
RETURN
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
ALL ( 'Table' ),
'Table'[Date]
>= DATE ( YEAR ( _min ) - 1, MONTH ( _min ), DAY ( _min ) )
&& 'Table'[Date]
<= DATE ( YEAR ( _max ) - 1, MONTH ( _max ), DAY ( _max ) )
)
)
Attached a sample file in the below, hopes to help you.
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.