Forum Discussion

chris_steins's avatar
chris_steins
New Member
5 years ago
Solved

DAX Formula

I'm looking to lookup a value in a data table and make a calculation based on it.

Below is my example table, where I'm trying to calculate the "percent Change" column where I want to look up in the table the same "Person" and same "Location" with a Rate of "0" and calculate the percent Change of "Value".  In the first row, it's simply dividing by itself since it has a rate of 0, but the next one it is taking the value (6) , and searching for the Value for the same location and Person and a Rate of 0 (Value of 5).  The final number here would then be subtracted from 1 to get the true value.

 

Any help would be appreciated, I'm struggling with the ability to lookup the value based on multiple columns and using it to calculate.

 

Example Data Table:

 

PersonRateValueLocationpercent Change
A05

UN

5/5=1
A16UN6/5=1.2
A24UN4/5=0.8
A06VD6/6=1
A17VD7/6=1.2
A25VD5/6=0/8
  • chris_steins 

    percent Change = 
    VAR num_ = Table1[Value]
    VAR denom_ =
        CALCULATE (
            AVERAGE ( Table1[Value] ),
            ALLEXCEPT ( Table1, Table1[Location] ),
            Table1[Rate] = 0
        )
    RETURN
          DIVIDE ( num_, denom_ ) 

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

  • chris_steins 

    See it all at work in the attached file.

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

     

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

    Cheers 

     

9 Replies

  • One more caveat to the question, the data table will have more than 1 entry with the same Person, Rate, and Location so I want to average the "Values" to use in the equation.

  • AlB's avatar
    AlB
    Community Champion

    Hi chris_steins 

    Try this for your calc column

    percent Change =
    VAR num_ = Table1[Value]
    VAR denom_ =
        CALCULATE (
            DISTINCT ( Table1[Value] ),
            ALLEXCEPT ( Table1, Table1[Location] ),
            Table1[Rate] = 0
        )
    RETURN
         ( DIVIDE ( num_, denom_ ) )

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

  • AlB's avatar
    AlB
    Community Champion

    chris_steins 

    See it all at work in the attached file.

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

  • The suggested code gives me the error of multiple values was supplied where a single value was expected.

     

    Probably because of my followup where there are multiple lines that need averaged.

     

    Another example table.

    PersonRateValue

    Location

    A05UN
    A16UN
    A24UN
    A06VD
    A17VD
    A25VD
    A08UN
    A15UN
    A26UN
    A07VD
    A18VD
    A29VD
    B08UN
    B17UN
    B25UN
    B09VD
    B18VD
    B27VD
    B04UN
    B15UN
    B22UN
    B08VD
    B16VD
    B28VD

     

  • AlB's avatar
    AlB
    Community Champion

    chris_steins 

    percent Change = 
    VAR num_ = Table1[Value]
    VAR denom_ =
        CALCULATE (
            AVERAGE ( Table1[Value] ),
            ALLEXCEPT ( Table1, Table1[Location] ),
            Table1[Rate] = 0
        )
    RETURN
          DIVIDE ( num_, denom_ ) 

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

  • AlB's avatar
    AlB
    Community Champion

    chris_steins 

    See it all at work in the attached file.

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

     

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

    Cheers 

     

  • Thoughts on what I need to add so that it only looks at the values coming from the same Parent?  Right now it is averaging all Parents with a Rate of 0.

  • AlB's avatar
    AlB
    Community Champion

    chris_steins 

    So is it solved now?

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers