Forum Discussion

Vladracs's avatar
Vladracs
Helper I
3 years ago

Divide 2 values on the same column?

Hello Expert,

 

I am still trying to solve this problem, which I probably should have explained in a better way.

 

Is there a way to dynamicaly calculate the variance between 2 row in a column, example:

 

CustomerVariable_ValueVariance
A2 
A4200%
A6150%
A3-50%

Noting that if I filter to only 2 items say the first and last, I'd get the result

CustomerVariable_ValueVariance
A2 
A3150%

 

thx in advance.

Vladimir

9 Replies

  • Your calculation is apparently incorrect, for example, (4-2)/2 = 100%
    Please create an index column in Power query and use the following measure:

    Pct change =
    VAR pval=LOOKUPVALUE('Table'[Variable_Value],'Table'[Index],SELECTEDVALUE('Table'[Index])-1)
    RETURN
    DIVIDE(CALCULATE(sum('Table'[Variable_Value]),ALLSELECTED('Table'[Index]))-pval,pval)
     

     

    • Vladracs's avatar
      Vladracs
      Helper I

      Hi, I'll give it a try it looks like it's going to work. 

      Just the calculation is not what I want 🙂 I want to know the difference in percentage from one value to the next,  4 is 200% of 2,  it's just 4/2 

      • Padycosmos's avatar
        Padycosmos
        Solution Sage
        You may try this
        Pct change =
        VAR pval=LOOKUPVALUE('Table'[Variable_Value],'Table'[Index],SELECTEDVALUE('Table'[Index])-1)
        RETURN
        DIVIDE(CALCULATE(sum('Table'[Variable_Value]),ALLSELECTED('Table'[Index])),pval)
    • Vladracs's avatar
      Vladracs
      Helper I

      Hi I am trying to understand how can I create a index that is "dynamic" meaning it will change based on the slicer. 
      If I add a fixed item column , when I filter the formulas above dont reflect what I need as they will still show an entry that is not on the filtered (sliced) table at the final page ğŸ˜•

  • Do you have a "order by" column for the table? OFFSET need a order of the values.

    • Vladracs's avatar
      Vladracs
      Helper I

      I ended up changing the table to not contain the date and calculate with filter:

       Var em % =
      VAR _MAX = maXX('Date','Date'[Ano])
      VAR _MIN = MINX('Date','Date'[Ano])
      RETURN
      100*(CALCULATE([Sum Values],FILTER(ALLSELECTED(Ranking[Date]),YEAR(Ranking[Date])=_MAX))/ CALCULATE([TSum Values],FILTER(ALLSELECTED(Ranking[Date]),YEAR(Ranking[Date])=_MIN))).

      It's not perfect as I had to add the meausure as a column, but I can hide and the end visual seems to be fine