Forum Discussion

zakkyang's avatar
zakkyang
Frequent Visitor
5 years ago
Solved

Group by Monthly Growth Rate

Hi,

 

I got the following sample data:

Product GroupProductMonthly Start DateSales Qty
Mobile Phone AMobile Phone A-11/1/2021100
Mobile Phone AMobile Phone A-12/1/2021120
Mobile Phone BMobile Phone B-11/1/202190
Mobile Phone BMobile Phone B-12/1/202178

 

 

What I want is to calculate the weekly product growth rate (below).

 

Product GroupProductMonth Start DateGrowth Rate
Mobile Phone AMobile Phone A-11/1/2021null
Mobile Phone AMobile Phone A-12/1/202120%
Mobile Phone BMobile Phone B-11/1/2021null
Mobile Phone BMobile Phone B-12/1/2021-13%

 

I guess I need to use groupby and sort order by the Month Start Date and calculate the rate.

 

 

The ultimate goal is to calculate the average weekly growth rate:

Product GroupProductAverage Weekly Growth Rate
Mobile Phone AMobile Phone A-1 
Mobile Phone BMobile Phone B-1 

 

 

Does anyone know the best way of calculating it?

 

Thanks.

  • Hi,  zakkyang 

    Try formulas as below:

    pre_Sales Qty = 
    VAR current_product =
        MAX ( 'Table'[Product] )
    VAR pre_month =
        DATEADD ( 'Table'[Monthly Start Date], -1, MONTH )
    VAR result =
        CALCULATE (
            MAX ( 'Table'[Sales Qty] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Product] = current_product
                    && 'Table'[Monthly Start Date] = pre_month
            )
        )
    RETURN
        result
    
    Growth Rate =
    DIVIDE ( SUM ( 'Table'[Sales Qty] ) - [pre_Sales Qty], [pre_Sales Qty] )
    

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

3 Replies

  • v-easonf-msft's avatar
    v-easonf-msft
    Icon for Community Support rankCommunity Support

    Hi,  zakkyang 

    Try formulas as below:

    pre_Sales Qty = 
    VAR current_product =
        MAX ( 'Table'[Product] )
    VAR pre_month =
        DATEADD ( 'Table'[Monthly Start Date], -1, MONTH )
    VAR result =
        CALCULATE (
            MAX ( 'Table'[Sales Qty] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Product] = current_product
                    && 'Table'[Monthly Start Date] = pre_month
            )
        )
    RETURN
        result
    
    Growth Rate =
    DIVIDE ( SUM ( 'Table'[Sales Qty] ) - [pre_Sales Qty], [pre_Sales Qty] )
    

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    • AllisonKennedy's avatar
      AllisonKennedy
      Icon for Community Champion rankCommunity Champion

      zakkyang  Great that this solution is working for you, just be careful that it's doing EXACTLY what you want.... 

       

      It is returning the MAX qty value from the previous month, which might not be the last date of the previous month - do you only have one record per month for each row? 

       

      Also be careful using

       MAX ( 'Table'[Product] )

       in that first line of code - it will return the last product alphabetically so may give funny results if there is more than one product selected.