Forum Discussion
calculating % from previous months value
Hi, I need a column that displays the previous month's incident figures in the same row as the current month so that I can calculate the percentage difference by month. However, for some reason, my measure is not working.
Here is my table
| Type | Date | ID |
| Incident | 01/04/2024 | 1 |
| Incident | 01/04/2024 | 2 |
| Incident | 01/04/2024 | 3 |
| Incident | 01/05/2024 | 4 |
| Incident | 01/06/2024 | 5 |
| Incident | 01/06/2024 | 6 |
| Incident | 01/06/2024 | 7 |
| Incident | 01/06/2024 | 8 |
| Incident | 01/07/2024 | 9 |
| Incident | 01/07/2024 | 10 |
| Type | Date | Count | Prev_Month | % Difference |
| Incident | 01/04/2024 | 3 | ||
| Incident | 01/05/2024 | 1 | 3 | 200% |
| Incident | 01/06/2024 | 4 | 1 | -75% |
| Incident | 01/07/2024 | 2 | 4 | 100% |
This was my measure, but for some reason, it was coming up as the same as the current month.
Thanks!
Hi RichOB ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you pankajnamekar25 for the prompt response.
Create the below measure to get the count of incidents.
Incident Count = DISTINCTCOUNT('Table'[ID])user the below measure to get the count of previous month countPrev_Month =CALCULATE(DISTINCTCOUNT('Table'[ID]),DATEADD('Table'[Date], -1, MONTH))Use below measure to get %difference.
% Difference =IF (ISBLANK([Prev_Month]),BLANK(),DIVIDE([Prev_Month] -[Incident Count],[Incident Count],BLANK()) * 100)I got the expected results using above measures. Attached the Pbix file for reference.If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thank you!!
7 Replies
- pankajnamekar25
Super User
Hello RichOB
Here you can try , Make sure you have a calendar table
Prev_Month =
CALCULATE(
DISTINCTCOUNT(Table[ID]),
DATEADD(DateTable[Date], -1, MONTH)
)
CurrentMonth = DISTINCTCOUNT(Table[ID])
% Difference =
DIVIDE(
[CurrentMonth] - [Prev_Month],
[Prev_Month],
BLANK()
)
Thanks,
Pankaj Namekar | LinkedInIf this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
- RichOB
Post Partisan
Hi pankajnamekar25, thanks for this. The table is linked to a calendar table and the current month works, but for some reason the previous month is showing as empty. Any ideas why? The measure is exactly what you've provided. Thanks
- ryan_mayu
Super User
could you pls provide your pbix file or some sample data?
- v-sathmakuri
Community Support
Hi RichOB ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you pankajnamekar25 for the prompt response.
Create the below measure to get the count of incidents.
Incident Count = DISTINCTCOUNT('Table'[ID])user the below measure to get the count of previous month countPrev_Month =CALCULATE(DISTINCTCOUNT('Table'[ID]),DATEADD('Table'[Date], -1, MONTH))Use below measure to get %difference.
% Difference =IF (ISBLANK([Prev_Month]),BLANK(),DIVIDE([Prev_Month] -[Incident Count],[Incident Count],BLANK()) * 100)I got the expected results using above measures. Attached the Pbix file for reference.If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thank you!!
- v-sathmakuri
Community Support
Hi RichOB ,
May I ask if the provided solution helped in resolving the issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you!!
- v-sathmakuri
Community Support
Hi RichOB ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you!!
- v-sathmakuri
Community Support
Hi RichOB ,
I hope the information provided is helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can find a solution faster.
Thank you!!