Forum Discussion
Adding conditional unique index column based on several criterias
The challenge is the need for having a column listing an existing unique ID or create new unique ID based on the following criteria:
- If the customer no is recognized, then use the existing unique ID , that is previously tied up to this number
- If the customer no is not recognized, then look up the email , and if this email is recognized, then use the unique ID that is previously tied up to this number.
- If neither the customer no , nor email matches previous records, then lookup phone AND name . If they match, then use existing unique ID , otherways create new unique ID .
The condtional column with the unique ID can either be added in the existingtable, which is a XML file that will be updated occassionally( loaded into Power BI. All columns are expanded). Or, the unique ID can be created in a new, separate table. I have lowercased names and emails in separate columns to ensure match.
The purpose is to always have a column or table with unique index numbers tied to a customer name, so that statistics are based on unique clients.
Is this possible, and if yes, what language would be the best option to use - M or DAX?
Any kind of concrete suggestion is highly appreciated as I have been searching in vain for anything that matches this.
Thanks a lot in advance. Marianne
- Thank you so much, looks very useful. I will try to implement this and get back with feedback as soon as possible. Thanks again!
10 Replies
- Greg_DecklerCommunity Champion
M or DAX is going to depend, can you post some sample data and an idea of your various tables involved? Not even sure what your unique index column is, is it just a unique integer number?
- MarianneElverHelper III
Hi, thanks for yor quick reply!
Sure, here is a little sample. The first four columns are currently provided and will receive new records when updated, and what I need is an additional column that, by checking for customer number or email, or name and phone, provides the ID that already exists, or creates a new unique interger number:
Customer Number email Customer name Phone ID 10135000 [email protected] Benny Johnson 4329463662 1 10031030 [email protected] Pete Madsen 4346123746 2 10056030 [email protected] Pete Madsen 4346123746 2 10164001 [email protected] Donna D. Nielsen 4346272296 3 10258006 [email protected] Sanny Peterson 4346414642 4 10258032 [email protected] Sanny Peterson 4346414642 4 Hope that clarifies it, otherwise please let me know!
Thanks again,
Marianne
- AnonymousNot applicable
Hi MarianneElver,
You can write a custom function to call the hash generate api, then input these condition columns to generate the unique code.
Regards,
Xiaoxin Sheng