Forum Discussion
Unique ID
- 10 years ago
buinia wrote:
In Excel this should be quite a straight forward formula of "if the Client Code is not blank, look up the Client Name and return Client Code but if it is blank look up both Client Name and Branch to return correct Client Code"
I just really struggle to put this is Power BI terms.
Thanks
Vivian
Your requirement is still confusing, if the dataset and the expectation is as below
Please follow steps
- create a proper relationship
- The DAX expression for two columns
Client Code2 = IF(ISBLANK(master[Client Code]),CONCATENATEX(branch,branch[Client Code],","),master[Client Code]&"") Sales2 = IF(ISBLANK(master[Client Code]),SUM(branch[Sales]),master[Sales])
- create a proper relationship
- 10 years ago
Hi Vivian,
I think I get it a bit better now, although I might be way off. Here's what my dataset looks like now:
Here's the updated version of the formula I provided yesterday:
Table 2 = UNION( SELECTCOLUMNS(FILTER('Table', 'Table'[Client Code] <> BLANK()), "Client Name", 'Table'[Client Name], "Client Code", 'Table'[Client Code], "Sales", 'Table'[Sales]), FILTER(ADDCOLUMNS(SELECTCOLUMNS(CROSSJOIN(DATATABLE("Index", INTEGER, {{1}, {2}, {3}}), FILTER('Table', 'Table'[Client Code] = BLANK())), "Client Name", 'Table'[Client Name], "Client Code", PATHITEM(SUBSTITUTE('Table'[Client Code 2], ",", "|"), [Index])), "Sales", LOOKUPVALUE('Table 3'[Sales], 'Table 3'[Client Name], [Client Name], 'Table 3'[Client Code], VALUE([Client Code]))), [Client Code] <> BLANK()) )Which gives this table:
Does that answer the question?
Hi,
Is the client code unique per Client Name? if yes, it's a one to many relationship depicted below:
Client Name | Client Id |
A | 1000 |
B | 1001 |
C | 1002 |
D | 1003 |
E | 1004 |
Branch Id | Branch Code | Client Id | Client Code |
2001 | (i) | 1001 | 1 |
2002 | (i) | 1002 | 2 |
2003 | (i) | 1003 | 3 |
2004 | (i) | 1004 | 4 |
2005 | (i) | 1005 | 5 |
2006 | (ii) | 1005 | 6 |
2007 | (iii) | 1005 | 7 |
If not, it becomes a many to many relationship where you have Client table, Branch table and a composite table that links the two. However, there is nothing wrong in having one table with repetitive records because it is what PBI does behind the scenes anyway :smileyvery-happy:
Let me know if this makes sense.
Thanks,
Fahd