Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Percentage Change showing incorrectly

I am having a problem showing the percentage change for when both values are 0. For example, if my figure for 2020 was 0, and my figure for 2021 was 0. I would want my % change visual to show 0% - as there has been no change. However it is showing -100%. This only affects figures where they are both 0, it works perfectly if both figures are 1 and it would show 0% change.

Below is my measure i'm using - could anyone advise as to why this could be happening?

% Vic Change =
DIVIDE(
CALCULATE(
DISTINCTCOUNT('Fact Incident'[Victim ID]),
FILTER('Date','Date'[Fiscal Year]=MAX('Date'[Fiscal Year])
)
),
CALCULATE(
DISTINCTCOUNT('Fact Incident'[Victim ID]),
FILTER('date','Date'[Fiscal Year]=MIN('Date'[Fiscal Year])))
,0)
- 1
As you can see in the screenshot below, i have two figures of 0 and the % change is showing as -100%:LloydThomas_0-1634036952620.png

 

1 ACCEPTED SOLUTION

@Anonymous 

 

Mathematically, the correct formula for calculating difference from previous year is:

 

(Cur Year - Prev Year)/Prev Year

 

Based on that, you should modify your formula:

 

% Vic Change =
VAR _Num = 

    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'Date''Date'[Fiscal Year] = MAX ( 'Date'[Fiscal Year] ) )
    )
VAR _Den = 
    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'date''Date'[Fiscal Year] = MIN ( 'Date'[Fiscal Year] ) )
    )
    
VAR _PercentChange = IFERROR((_Num-_Den)/_Den ,0)
RETURN
_PercerntChange

 

Note: You may want to assign appropriate variable names.

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂 (Hit the thumbs up button!)
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)


https://www.vivran.in/

Connect on LinkedIn

View solution in original post

7 REPLIES 7
vivran22
Community Champion
Community Champion

Hello @Anonymous 

 

I believe you need to modify the formula:

% Vic Change =
VAR _Num = 

    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'Date', 'Date'[Fiscal Year] = MAX ( 'Date'[Fiscal Year] ) )
    )
VAR _Den = 
    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'date', 'Date'[Fiscal Year] = MIN ( 'Date'[Fiscal Year] ) )
    )
    
VAR _PercentChange = IFERROR(_Num/_Den - 1,0)
RETURN
_PercerntChange

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂 (Hit the thumbs up button!)
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)


https://www.vivran.in/

Connect on LinkedIn

Anonymous
Not applicable

Hi @vivran22 thanks for this. Unfortunately the end result is the same  = -100%.

@Anonymous 

 

Mathematically, the correct formula for calculating difference from previous year is:

 

(Cur Year - Prev Year)/Prev Year

 

Based on that, you should modify your formula:

 

% Vic Change =
VAR _Num = 

    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'Date''Date'[Fiscal Year] = MAX ( 'Date'[Fiscal Year] ) )
    )
VAR _Den = 
    CALCULATE (
        DISTINCTCOUNT ( 'Fact Incident'[Victim ID] ),
        FILTER ( 'date''Date'[Fiscal Year] = MIN ( 'Date'[Fiscal Year] ) )
    )
    
VAR _PercentChange = IFERROR((_Num-_Den)/_Den ,0)
RETURN
_PercerntChange

 

Note: You may want to assign appropriate variable names.

 

Cheers!
Vivek

If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂 (Hit the thumbs up button!)
If it doesn't, then please share a sample data along with the expected results (preferably an excel file and not an image)


https://www.vivran.in/

Connect on LinkedIn

Anonymous
Not applicable

@Anonymous You can add third parameter (write there 1) in DIVIDE function (what function returns when there is dividing by zero).

Anonymous
Not applicable

Hi @Anonymous , how would this look inside my current measure please? Thanks

Anonymous
Not applicable

% Vic Change =
DIVIDE(
  CALCULATE(
    DISTINCTCOUNT('Fact Incident'[Victim ID]),
    FILTER('Date','Date'[Fiscal Year]=MAX('Date'[Fiscal Year])
    )
  ),
  CALCULATE(
    DISTINCTCOUNT('Fact Incident'[Victim ID]),
    FILTER('date','Date'[Fiscal Year]=MIN('Date'[Fiscal Year])
    )
  )
,1)
- 1
Anonymous
Not applicable

That has gave the same result as mine did @Anonymous = -100%

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.