Lynn234
Lynn234

Reputation: 43

How to return a value from a row based on another column in power BI?

In BI, is there a way to write a function that looks at Name 2 and pulls the score from the second column for that individual? Any help would be greatly appreciated!

Name Score Name 2 Score 2
Bob 100 Sue
Sue 80 Nick
Nick 50 Bob

Upvotes: 2

Views: 17625

Answers (2)

RADO
RADO

Reputation: 8148

If you want to implement it as a calculated column in your data model:

Score 2 =
VAR Current_Name = Table[Name 2]
RETURN
    CALCULATE ( SUM ( Table[Score] ), ALL ( Table ), Table[Name] = Current_Name )

If you want to implement it as a measure:

Score 2 =
CALCULATE (
    SUM ( Table[Score] ),
    ALL ( Table )
    Table[Name] IN VALUES ( Table[Name 2] )
)

enter image description here

Upvotes: 3

smpa01
smpa01

Reputation: 4346

You sure can with the following measure

_score2 =
SUMX (
    'fact',
    VAR _0 = 'fact'[Name 2]
    VAR _1 =
        CALCULATE (
            CALCULATE ( SUM ( 'fact'[Score] ), 'fact'[Name] = _0 ),
            ALL ( 'fact' )
        )
    RETURN
        _1
)

Solution

Upvotes: 0

Related Questions