Forum Discussion

allora's avatar
allora
Frequent Visitor
3 years ago

Getting average profit during different time periods

I have a dataset that follows this general structure: We have data on numerous business (clients) and their sales/profit trends over various months.


Client_Sales

ClientMonthYearSalesProfit
ABC01/01/20228001000
ABC02/01/20229001200
ABC03/01/2022450800
ABC04/01/20222391239
ABC05/01/2022123112312
ABC06/01/2022400231
ABC07/01/2022450010020
ABC08/01/2022450230
ABC09/01/20222901234
ABC10/01/202276300
ABC11/01/2022891230
ABC12/01/20222104500

 

I have a second table that looks like this: All of the business in the the above table were recently 'sold' or 'changed management'. 

Client_Acquisition:

ClientDate of Sale
ABC05/15/2022

 

  • I would like to see how profits were affected before during and after the sale of the business. Specifically, I want to create a line graph that shows what the profit was:
    • 12 months rolling profit ending 3 months prior to the date sale. In this case, the sale date was 5/15/2022. So I want average 12 month rolling data up until  02/01/2022.
    • What profits were the month of the sale. In this case the full month of May 2022.
    • 3 months post sale. In this case it would be total average profit for June, July, and August 2022.
    • Month by month after that time point. September, October, November, and December 2022 also as separate points.

Any help on how to create a function or equation to do this would be immensely helpful.

1 Reply

  • allora , try like , with help from date table

     

    12 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[profilt])))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

     

    3 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[profilt])))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),3,MONTH))

     

    Rolling Months Formula: https://youtu.be/GS5O4G81fww

     

    You can consider Window function too

    Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

     

    Rolling 12 = CALCULATE(AverageX(Values('Date'[MONTH Year]),calculate(Sum('Table'[profilt]))), WINDOW(-11,REL, 0, REL, ADDCOLUMNS(ALLSELECTED('Date'[Month Year],'Date'[Month Year Sort] ),ORDERBY([Month Year Sort],asc)))