Forum Discussion

sd89's avatar
sd89
Regular Visitor
5 years ago
Solved

Computing Year on Year Sales Growth based on dynamic date range selection

Hi   I have a data which consists of sales and a date range. I want to compute year on year growth for a particular date range. For example, if I select date range 3-3-2020 to 7-8-2020 using a slic...
  • v-yingjl's avatar
    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 Li

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.