Forum Discussion
Add columns from related rows in another table
I have been using the matrix visual to display a set of columns from a related table. Table A contains columns ID, Name, Title. Table B contains columns ID, Category, Amount. There are 3-4 records in Table B for each ID in Table A. I put Name and Title as rows in my visual, Category as column and Amount as the value. This works okay, except I want to reorder the columns and I'd like to put Title as the last column in the visual. I don't think this is possible with a matrix, so now I am considering other possibilities.
One solution is adding columns in the data model to Table A for each Category and pulling in the Amount for each and then just using a standard table visual, but I'm not sure how to do this. I'm also not sure if it is the best approach.
Table A
Table B
Desired result
8 Replies
- Ashish_Mathur
Super User
Hi,
This works with just one measure and no transformation in the Query Editor. Download the file from here.
Hope this helps.
- jdbuchanan71
Super User
Nice! Ashish_Mathur Tricking the row total into returning the title.
- Ashish_Mathur
Super User
Thank you.
- jdbuchanan71
Super User
Anonymous
One thing you could do is split the category into 3 measures so they could be pulled into a table visual without needing the category column.
First a measure just to sum the amount.
Total Amount = SUM ( TableB[Amount] )Then the three measures for the categories
Base = CALCULATE ( [Total Amount], KEEPFILTERS ( TableB[Category] = "Base" ) )Tax = CALCULATE ( [Total Amount], KEEPFILTERS ( TableB[Category] = "Tax") )Tip = CALCULATE ( [Total Amount], KEEPFILTERS ( TableB[Category] = "Tip" ) )Then in our table visual you pull in Name from the column, the 3 measures above (Base, Tax, Tip) and then the Title column
- mwegener
Most Valuable Professional
- AnonymousNot applicable
Hi Anonymous,
To fix this, I would pivot your column category in Power Query Editor. In Power Query Editor you would highlight your category column, then go to Transform > Any Column > Pivot Column in the ribbon. You will get a box like the one below:
Use your Amount column as the values and click OK. When you do this you will get a table that looks like the one below:
Once you close and apply your work in the query editor, you will be able to easily put this information into the values of a table visual and move them in the order that you want.
Hope this helps!
- mwegener
Most Valuable Professional
Hi Anonymous ,
did you solve your problem?
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.