Forum Discussion
Test on two column against two columns from another table
Hi,
I have an interactions table with
Manager | Agent
fred bloggs | Joe Bloggs
Joanne bloggs | Joe Bloggs
And a current manager table with
Manager | Agent
fred bloggs | Joe Bloggs
I want to create a column on the interactions table which shows what the current manager is...in this case Fred is the current manager.
Thanks
Chris
6 Replies
- jaweher899
Impactful Individual
You can achieve this by creating a calculated column in your interactions table that compares the Manager and Agent columns in both tables. Here's an example of how you can create the calculated column:
In Power BI Desktop, open the interactions table.
In the Home tab, click on "New Column" to create a new calculated column.
In the formula bar, enter the following DAX formula:
= IF(AND('interactions'[Manager] = 'current manager'[Manager] , 'interactions'[Agent] = 'current manager'[Agent]), 'interactions'[Manager], BLANK())
This formula uses the IF function to compare the Manager and Agent columns in both tables and returns the Manager column from the interactions table if both columns match, otherwise it returns BLANK().
Press Enter to create the calculated column.
Rename the column to something like "Current Manager".
It's also important to note that the formula above is assuming that your tables and columns are named "interactions" and "current manager", you'll need to adjust the formula accordingly if the names are different.
You can also use the RELATED function to achieve this result, by creating a relationship between the two tables based on Manager and Agent columns, and then using RELATED('current manager'[Manager]) in the calculated column.
= RELATED('current manager'[Manager])
By using this formula, you don't have to compare the columns, it will automatically show the current manager based on the existing relationship.
- jak8282
Helper III
Hi jaweher899
It cant seem to find the current manager table even though it exists when I try and input your code.
IF(AND('interactions'[Manager] = 'current manager'[Manager] , 'interactions'[Agent] = 'current manager'[Agent]), 'interactions'[Manager], BLANK())Thanks
Chris
- jaweher899
Impactful Individual
jak8282 Please accept my answer if it resolves your issue.
- PowerBIEnthu
Resolver I
CALCULATE ( FIRSTNONBLANK ( Manager[Interactions], 1 ), FILTER ( ALL ( current Manager Table), Manager[Agent] = Current Manager Table[Agent] ) )
Try something like this- jak8282
Helper III
Hi PowerBIEnthu ,
That is only filtering on the agent, I need it to filter on manager and agent.
Thanks
Chris