Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I'm trying to add the name of the employee who created an entry in our Sales Order dataset in PowerBI. The relevant columns are as below:
SALESORDER
...
SALESPERSON_ID VARCHAR(20)
EMPLOYEE
OLD_FORMAT_EMPLOYEE_ID VARCHAR(20)
NEW_FORMAT_EMPLOYEE_ID INT
DISPLAYNAME VARCHAR(200)
...
In SQL I would do this by the below:
SELECT SALESORDER..., EMPLOYEES.DISPLAYNAME FROM SALESORDER LEFT JOIN EMPLOYEE ON SALESORDER.SALESPERSON_ID = CAST(EMPLOYEE.NEW_FORMAT_EMPLOYEE_ID AS VARCHAR(20)) OR SALESORDER.SALESPERSON_ID = EMPLOYEE.OLD_FORMAT_EMPLOYEE_ID
To do this in PowerBI I could either use the above, which feels like a cheat (I'm trying to become competent in PowerBI), or add a column with a DAX statement like below (which gives an error comparing Text and Number, which confuses me because I've changed the data type on 'Employee'[NEW_FORMAT_EMPLOYEE_ID] to Text in the Advanced Editor)
IF( IFERROR(VALUE('Sales Order'[SALESPERSON_ID]), -1) = -1, LOOKUPVALUE( 'Employee'[DISPLAYNAME], 'Employee'[OLD_FORMAT_EMPLOYEE_ID], 'Sales Order'[SALESPERSON_ID] ), LOOKUPVALUE( 'Employee'[DISPLAYNAME], 'Employee'[NEW_FORMAT_EMPLOYEE_ID], 'Sales Order'[SALESPERSON_ID] ) )
I'd appreciate any assistance getting this join/lookup to work in PowerBI.
Thanks,
Andrew
Solved! Go to Solution.
Hi, @andrewpirie
First make sure that the data type of columns OLD_FORMAT_EMPLOYEE_ID and NEW_FORMAT_EMPLOYEE_ID in table EMPLOYEE are both text.
Add a calculated column in table SALESORDER:
Name = IF( LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[NEW_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID])= "", LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[OLD_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID]), LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[NEW_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID]) )
Best regards,
Yuliana Gu
Hi, @andrewpirie
First make sure that the data type of columns OLD_FORMAT_EMPLOYEE_ID and NEW_FORMAT_EMPLOYEE_ID in table EMPLOYEE are both text.
Add a calculated column in table SALESORDER:
Name = IF( LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[NEW_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID])= "", LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[OLD_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID]), LOOKUPVALUE(EMPLOYEE[DISPLAYNAME],EMPLOYEE[NEW_FORMAT_EMPLOYEE_ID],SALESORDER[SALESPERSON_ID]) )
Best regards,
Yuliana Gu
Thanks Yuliana_Gu, that's a brilliant solution!
Andrew
What about the option of using the Merge Queires option in the Query Editor?
That will give you all the required options as shown below.
@andrewpirie Make sure data type on both the columns is same ie salesperson_id and new_format_employee_id.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |