Forum Discussion
How to calculate % increase
- 9 years ago
Took me much digging and searching but i found a solution. And now looking at the solution, it seems quite easy. For me not so much because i am not an excel warrior and have no prior dax programming experience.
To summarize, i have a sales table that is aggregated monthly. My requirement is to show monthly increase/decrease in sales which can be filtered by region. additionally, i want to show the percent increase from the prior year. i added to my sales agg, the delta between this month's sales and the prior month. i also added the prior years sales amount. all this is stored at the month/sales region grain. i allow the report to restrict dates to year, quarter, or month. Percent increase is the sum of the deltas divided by the prior year sales amount. if i select a year, its 12 months of deltas divided by prior year. if i select a quarter its 3 months of deltas divided by prior year. problem is the prior year amount repeats across all monthly records, so when i select 3 months powerbi wants to sum the deltas of each month but also wants to sum the prior year amount of all 3 months. obviously that will not work.
my solution is to create custom measures:
first calculate the prior year amount that will not change regardless of how many months are selected:
Sales Prior Year Amount = sum([sales_last_year_amt])/distinctcount([month_end_date])
next calculate the percent increase, using prior year sales amount calculated above:
Sales Percent Increase = divide(sum([sales_delta_amt]),[Sales Prior Year Amount])
Easy solution now that i look at it, but it took me 2 days to figure it out :)
My report is using 2 waterfall visuals, one for the sales amount increase/decrease, one for the sales % increase/decrease. when i select a year, it looks great, shows starting point to ending and all the 12 changes between. i also have a summary card that shows the sales amount beginning, ending, delta, and % increase. I can slice by sales region and/or by time. though the report will not work properly if we span years (as the prior year sales amount will change across years and foul the results). my business users understand this and use the report as intended. I may add some code that prevents the report from calculating percentages when multiple years are selected.
thanks!
Took me much digging and searching but i found a solution. And now looking at the solution, it seems quite easy. For me not so much because i am not an excel warrior and have no prior dax programming experience.
To summarize, i have a sales table that is aggregated monthly. My requirement is to show monthly increase/decrease in sales which can be filtered by region. additionally, i want to show the percent increase from the prior year. i added to my sales agg, the delta between this month's sales and the prior month. i also added the prior years sales amount. all this is stored at the month/sales region grain. i allow the report to restrict dates to year, quarter, or month. Percent increase is the sum of the deltas divided by the prior year sales amount. if i select a year, its 12 months of deltas divided by prior year. if i select a quarter its 3 months of deltas divided by prior year. problem is the prior year amount repeats across all monthly records, so when i select 3 months powerbi wants to sum the deltas of each month but also wants to sum the prior year amount of all 3 months. obviously that will not work.
my solution is to create custom measures:
first calculate the prior year amount that will not change regardless of how many months are selected:
Sales Prior Year Amount = sum([sales_last_year_amt])/distinctcount([month_end_date])
next calculate the percent increase, using prior year sales amount calculated above:
Sales Percent Increase = divide(sum([sales_delta_amt]),[Sales Prior Year Amount])
Easy solution now that i look at it, but it took me 2 days to figure it out :)
My report is using 2 waterfall visuals, one for the sales amount increase/decrease, one for the sales % increase/decrease. when i select a year, it looks great, shows starting point to ending and all the 12 changes between. i also have a summary card that shows the sales amount beginning, ending, delta, and % increase. I can slice by sales region and/or by time. though the report will not work properly if we span years (as the prior year sales amount will change across years and foul the results). my business users understand this and use the report as intended. I may add some code that prevents the report from calculating percentages when multiple years are selected.
thanks!
- v-huizhn-msft9 years agoMicrosoft Employee
Hi ptnewman,
I am very gald you have resloved your issue, please mark your solution as answer. So that other people having similar problems will find workaround easily. Thanks for understanding.
Best Regards,
Angelia