Forum Discussion

RichOB's avatar
RichOB
Icon for Post Partisan rankPost Partisan
1 year ago
Solved

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

TypeDateID
Incident01/04/20241
Incident01/04/20242
Incident01/04/20243
Incident01/05/20244
Incident01/06/20245
Incident01/06/20246
Incident01/06/20247
Incident01/06/20248
Incident01/07/20249
Incident01/07/202410

 

TypeDate CountPrev_Month% Difference
Incident01/04/20243  
Incident01/05/202413200%
Incident01/06/202441-75%
Incident01/07/202424100%

 

This was my measure, but for some reason, it was coming up as the same as the current month.

Prev_Month = CALCULATE(DISTINCTCOUNT(Table[ID]), DATEADD(Table[Date].[Date], -1, 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 count
     
    Prev_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

  • 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 | LinkedIn

    If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

    • RichOB's avatar
      RichOB
      Icon for Post Partisan rankPost 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's avatar
        ryan_mayu
        Icon for Super User rankSuper User

        could you pls provide your pbix file or some sample data?

  • v-sathmakuri's avatar
    v-sathmakuri
    Icon for Community Support rankCommunity 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 count
     
    Prev_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's avatar
    v-sathmakuri
    Icon for Community Support rankCommunity 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's avatar
    v-sathmakuri
    Icon for Community Support rankCommunity 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's avatar
    v-sathmakuri
    Icon for Community Support rankCommunity 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!!