Forum Discussion

deaconb's avatar
deaconb
Helper I
2 years ago
Solved

Column value from row

We have training data that looks like below:

NameRoleResponseIDTrainer
ATrainee7125417Z
ZTrainer7125417 
ATrainee7125461Y
YTrainer7125461 
BTrainee7125955X
XTrainer7125955 
BTrainee7125978X
XTrainer7125978 

 

 

 

A Trainee can complete several different training events either with a different Trainer each time or the same trainer over multiple times. Each time a Trainee compelete a training, the training event is stored as a transaction in the database by "ResponseID"; these increment up 1 for each training event, so it can be used to order things chronologically 1-N, where item 1 was completed before item 2, etc. The trainer and trainee are logged to the same "ResponseID" and differentiated by the "Role" column.

 

I'd like to have the data as depicted above in the "Trainer" column. So essentially, I want to have a single row of each "ResponseID" by making the "Trainer" a column instead of keeping it as "second" row.

 

I'm pretty new to Power BI and I'm just at a loss for how to even accomplish this. Any help or guidance with this is greatly appreciated!! 

10 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi deaconb 
    Hope this is what you're looking for

    Table 2 = 
    SUMMARIZE ( 
        'Table',
        'Table'[ResponseID],
        "Trainee", MAXX ( FILTER ( 'Table', 'Table'[Role] = "Trainee" ), 'Table'[Name] ),
        "Trainer", MAXX ( FILTER ( 'Table', 'Table'[Role] = "Trainer" ), 'Table'[Name] )
    )
    • deaconb's avatar
      deaconb
      Helper I

      hey - this result is exactly what I'm looking for. However, when I insert it into my query as a column, it gives me an error of a cyclic reference. 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi deaconb ,
    Thanks to tamerj1 and DataNinja777  for thier methods.
    Here's how I solved it
    Create column

    Trainer = 
    VAR _result = 
    CALCULATE(
        MAX('Table'[Name]),
        FILTER(
            ALLEXCEPT(
                'Table',
                'Table'[ResponseID]
            ),
            'Table'[Role] = "Trainer"
        )
    )
    RETURN
    IF(
        'Table'[Role] = "Trainee",
        _result,
        BLANK()
    )

    Create a calculated table

    Result = 
    SELECTCOLUMNS(
        FILTER('Table','Table'[Trainer] <> BLANK()),
        "ResponseID",'Table'[ResponseID],
        "Trainee",'Table'[Name],
        "Trainer",'Table'[Trainer]
    )

    Final output

    Best regards,

    Albert He

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • deaconb's avatar
      deaconb
      Helper I

      Hi DataNinja777 this works as a new Column in Power BI table view, but it isn't working as a Custom Column step in Power Query (I understand they are different).

       

      I'd prefer to do this in Power Query so I can then delete the "Trainer" row all togther, after the new column is created, which makes the remaining dataset 50% less rows as the only difference between the raw dataset rows is the Trainer row and Trainee row. 

       

      Do you know what modifications I'd need to make to get this to work through Power Query?