Forum Discussion
Adding new column based on another column criteria on the same table
Hello, I have this problem where I wanted to add a new column based on the criteria from another column on the same table.
Below is what my table looks like.
| Number | Link Type | Party ID |
| 50095 | RC | |
| 50095 | AD | |
| 50095 | COM | |
| 50095 | SM | 12345 |
| 50095 | WSM | 67890 |
Here is the result I wanted to achieve. Add WSM column.
| Number | Link Type | Party ID | WSM |
| 50095 | RC | 67890 | |
| 50095 | AD | 67890 | |
| 50095 | COM | 67890 | |
| 50095 | SM | 12345 | 67890 |
| 50095 | WSM | 67890 | 67890 |
Is this possible in Power BI? Appreciate your help and response. Thank you.
Let me know if you need more information.
Thanks,
MarkQ
12 Replies
- lbendlin
Super User
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjUwsDRV0lEKcgYSCkqxOgghRxcMIWd/XwyxYJCQoZGxiSmKcDhY3MzcwtJAKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Link Type" = _t, #"Party ID" = _t]), #"Added Custom" = Table.AddColumn(Source, "WSM", each Table.SelectRows(Source,each [Link Type]="WSM"){0}[Party ID]) in #"Added Custom"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
- markquisquirinFrequent Visitor
Hi Ibendlin, wow! This worked, thanks. 🙂
- AnonymousNot applicable
Hi markquisquirin ,
Please have a try.
Create a measure.
Measure = MAXX(FILTER(ALL('Table'),'Table'[Number]=SELECTEDVALUE('Table'[Number])),'Table'[Party ID])Or a column.
Column = MAXX(FILTER(ALL('Table'),'Table'[Number]=EARLIER('Table'[Number])),'Table'[Party ID])How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ PollyIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- markquisquirinFrequent Visitor
Hi v-polly-msft, I am looking for a DAX solution as well, thanks for this. I will try and let you know the result.
- lbendlin
Super User
if you want to do that in DAX you can use REMOVEFILTERS or otherwise bend the column filter to the WSM value.
- AnonymousNot applicable
Hi markquisquirin ,
Please have a try.
Create a measure.
measure = CALCULATE ( MAX ( 'Table'[Party ID] ), FILTER ( ALL ( 'Table' ), 'Table'[Number] = SELECTEDVALUE ( 'Table'[Number] ) && 'Table'[Link] = "WSM" ) )Or a column.
Column = CALCULATE ( MAX ( 'Table'[Party ID] ), FILTER ( ALL ( 'Table' ), 'Table'[Number] = EARLIER ( 'Table'[Number] ) && 'Table'[Link] = "WSM" ) )Best Regards
Community Support Team _ PollyIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- lbendlin
Super User
Please specify if you want it as a column or a measure.