Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
KyawMyoTun
Helper III
Helper III

Create Customer table from Sale table with multiple Customer Names

Dear Experts,

  I am trying to create a new unique "Customer" table from existing Sale table in dax.
Actully it can be created by using Summarize function with the reuqired columns.
The problem I am facing is some customers have changed their name over time.
So, the Summarize function can't handle the duplicate names.
The sale table is Direct Query Mode(Power Bi Dataset) and can't create duplicate tables in power query.
I'd like to get the Customer with lastest Customer Name.
The Sale Table

KyawMyoTun_0-1687503361141.png


The expected Customer Table

KyawMyoTun_2-1687503527501.png

 

Thanks a lot for your help.

Regards,
KMT

1 ACCEPTED SOLUTION

Dear @DOLEARY85 ,
I have tried and some old names still because of FIRSTNONBLANK function I think.
So, I tried with LASTDATE function of Order date and it gave me the expected results.
Pbix file is not able to share for me.
So, Please check the screenshot and let me know your thought.
Thanks a lot for your help.

KyawMyoTun_0-1687703617925.pngKyawMyoTun_1-1687703661657.png

 

KyawMyoTun_2-1687703698326.png

 



Best Regards,
KMT

View solution in original post

14 REPLIES 14
DOLEARY85
Super User
Super User

Hi,

 

try creating a new table with this, which works with your current data:

 

New Table =
ADDCOLUMNS(
DISTINCT('Table'[CUSTOMER ID]),
"Customer Name", CALCULATE(MAX('Table'[CUSTOMER NAME]), ALLEXCEPT('Table', 'Table'[CUSTOMER ID])))
 
DOLEARY85_0-1687508242325.png

 

Alternatively try:

  

New Table =
ADDCOLUMNS(
DISTINCT('Table'[CUSTOMER ID]),
"Customer Name", CALCULATE(FIRSTNONBLANK('Table'[CUSTOMER NAME],CALCULATE(MAX('Table'[ORDER ID])))))

 

 

DOLEARY85_1-1687509833231.png

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Dear @DOLEARY85 ,

  Thanks a lot for your help and it is working properly.
I'd like to request you another one becuase there have some blank customers in sale table.
I'd like to remove those blank customers before creating customer table.
Can you please help for this also? Thanks.

Regards,
KMT

How does the data look in the sales table for the blank customers, is it both the customer id and name that's blank?

Yes, both customer id and customer names are the blank
becuase of some manual invoicing.
I'd like to ignore the customers for those invoices. Thanks.

Sorry i think i may have misread what you wanted, so if you wanted another version of the table with those 5 fields but without blank customers you could summarize a new table:

 

Table 2 = FILTER(SUMMARIZE('Table','Table'[CUSTOMER ID],'Table'[CUSTOMER NAME],'Table'[ORDER DATE],'Table'[ORDER ID],'Table'[SALE AMOUNT]),not('Table'[CUSTOMER ID]=""))
 
which changes:
 
DOLEARY85_1-1687514451160.png

 

 
to:
DOLEARY85_0-1687514419775.png

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Dear @DOLEARY85 ,

Actually I only want two columns with Customer ID and Custoumer Name
Where both are not blanks.
The below code are nearly working properly but some customers still getting old name.

FILTER(ADDCOLUMNS(
DISTINCT('Table'[CUSTOMER ID]),
"Customer Name", CALCULATE(FIRSTNONBLANK('Table'[CUSTOMER NAME],CALCULATE(MAX('Table'[ORDER ID]))))),NOT('Table'[CUSTOMER ID]=""))

I think it is better to filter the max Order Date than Order ID because
some reversal sale comes by larger order ID. Thanks.
Please help again.

Okay, it's an easy change then, just change Order ID to Order Date and it'll work the same way:

 

New Table =
FILTER(ADDCOLUMNS(
DISTINCT('Table'[CUSTOMER ID]),
"Customer Name", CALCULATE(FIRSTNONBLANK('Table'[CUSTOMER NAME],CALCULATE(MAX('Table'[ORDER DATE]))))),NOT('Table'[CUSTOMER ID]=""))
 
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

I've test that one but still some customers getting old name.

Could you share a couple of the records with the old and new names so i can test why they're not changing. Or could you share you PBIX file?

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Thanks a lot for your help.
I'll share the pbix soon and it might delay some time for other urget matter.
Thanks a lot for your help again.

Regards,
KMT

Okay try chaning the new table formula to(i've added in bold the additions to a previous table:

 

New Table =
FILTER(ADDCOLUMNS(
DISTINCT('Table'[CUSTOMER ID]),
"Customer Name", CALCULATE(FIRSTNONBLANK('Table'[CUSTOMER NAME],CALCULATE(MAX('Table'[ORDER ID]))))),NOT('Table'[CUSTOMER ID]=""))
 
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

Dear @DOLEARY85 ,
I have tried and some old names still because of FIRSTNONBLANK function I think.
So, I tried with LASTDATE function of Order date and it gave me the expected results.
Pbix file is not able to share for me.
So, Please check the screenshot and let me know your thought.
Thanks a lot for your help.

KyawMyoTun_0-1687703617925.pngKyawMyoTun_1-1687703661657.png

 

KyawMyoTun_2-1687703698326.png

 



Best Regards,
KMT

Hi,

 

yeah that looks good, FIRSTNONBLANK should have worked too due to it being filtered by the max order date. Without seeing the PBIX file i'm not sure why that didn't work but if adapting my solution with LASTDATE gives you what you need then that's great. Glad it worked.

 

happy to help 🙂

Dear @DOLEARY85 ,

  The expected result is coming of adapting your solution.

Thanks for helping. Happy learning.

Regards,
KMT

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.