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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
deaconb
Frequent Visitor

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!! 
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @deaconb 

There are many ways to achive your required output, and one example is as shown below:

DataNinja777_0-1714792771925.png

I attach an example pbix file.  

View solution in original post

10 REPLIES 10
v-heq-msft
Community Support
Community Support

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

vheqmsft_0-1714988697925.png

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

tamerj1
Super User
Super User

Hi @deaconb 
Hope this is what you're looking for

1.png

Table 2 = 
SUMMARIZE ( 
    'Table',
    'Table'[ResponseID],
    "Trainee", MAXX ( FILTER ( 'Table', 'Table'[Role] = "Trainee" ), 'Table'[Name] ),
    "Trainer", MAXX ( FILTER ( 'Table', 'Table'[Role] = "Trainer" ), 'Table'[Name] )
)

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. 

@deaconb 

What is your query?

The source data is a full dataset of training information. I truncated the data in my example to only the columns I care about/need to work with. 

 

When I applied your logic as a Custom Column step in Power Query, I received this error: 

Expression.Error: A cyclic reference was encountered during evaluation.

 

When I applied your logic as a new Column in Power BI table view, I received this error:

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

@deaconb 
You can simply group by Response ID and use if statement in the aggregation.

DataNinja777
Super User
Super User

Hi @deaconb 

There are many ways to achive your required output, and one example is as shown below:

DataNinja777_0-1714792771925.png

I attach an example pbix file.  

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?

Hi @deaconb 

You have your required output in dax formula from multiple people, but if you want to use Power Query instead, you can create a table like below using Power Query Ribbon clicking technique.  

DataNinja777_0-1715003486572.png

Best regards,

Thanks. I'll just use the dax output.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.