Calculated column to get a customer name

LBala

New Member
Joined
Apr 3, 2014
Messages
22
Hi all;
I am working with a power pivot report with a table showing the sales of specific products, if the product was already delivered to the customer and the estimated delivery date. This is the table:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Product[/TD]
[TD]Customer name[/TD]
[TD]Delivered[/TD]
[TD]Estimated delivery date[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]Susan[/TD]
[TD]Yes[/TD]
[TD]03/15/18[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]Mary[/TD]
[TD]Yes[/TD]
[TD]04/15/18[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]John[/TD]
[TD]No[/TD]
[TD]06/15/18[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]David[/TD]
[TD]No[/TD]
[TD]07/15/18[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Andrew[/TD]
[TD]Yes[/TD]
[TD]04/20/18[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Shannon[/TD]
[TD]Yes[/TD]
[TD]05/20/18[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Anna[/TD]
[TD]No[/TD]
[TD]06/20/18[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Luke[/TD]
[TD]No[/TD]
[TD]07/20/18[/TD]
[/TR]
</tbody>[/TABLE]

I need to create a calculated column showing the name of the next customer to receive the product showing in each row. The table with the calculated column looks like this:

[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Product[/TD]
[TD]Customer name[/TD]
[TD]Delivered[/TD]
[TD]Estimated delivery date[/TD]
[TD]Next customer to receive the product[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]Susan[/TD]
[TD]Yes[/TD]
[TD]03/15/18[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]Mary[/TD]
[TD]Yes[/TD]
[TD]04/15/18[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]John[/TD]
[TD]No[/TD]
[TD]06/15/18[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD]TV[/TD]
[TD]David[/TD]
[TD]No[/TD]
[TD]07/15/18[/TD]
[TD]John[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Andrew[/TD]
[TD]Yes[/TD]
[TD]04/20/18[/TD]
[TD]Anna[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Shannon[/TD]
[TD]Yes[/TD]
[TD]05/20/18[/TD]
[TD]Anna[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Anna[/TD]
[TD]No[/TD]
[TD]06/20/18[/TD]
[TD]Anna[/TD]
[/TR]
[TR]
[TD]Computer[/TD]
[TD]Luke[/TD]
[TD]No[/TD]
[TD]07/20/18[/TD]
[TD]Anna[/TD]
[/TR]
</tbody>[/TABLE]


Explaining:

For the product "TV": John and David have not received it yet (Delivered = "No") and John is the next customer to receive it (Estimated delivery date = 06/15/18).

For the product "Computer": Anna and Luke have not received it yet (Delivered = "No") and Anna is the next customer to receive it (Estimated delivery date = 06/20/18).

What DAX formula should I enter in the column "Next customer to receive the product" to retrieve the customer name?

Thanks.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
NextCustomer =
[COLOR=#0070ff]CALCULATE[/COLOR][COLOR=#969696] ([/COLOR]
    [COLOR=#0070ff]VALUES[/COLOR][COLOR=#969696] ([/COLOR] Data[Customer name] [COLOR=#969696])[/COLOR],
    [COLOR=#0070ff]TOPN[/COLOR][COLOR=#969696] ([/COLOR]
        [COLOR=#ee7f18]1[/COLOR],
        [COLOR=#0070ff]FILTER[/COLOR][COLOR=#969696] ([/COLOR]
            [COLOR=#0070ff]ALL[/COLOR][COLOR=#969696] ([/COLOR]
                Data[Product],
                Data[Customer name],
                Data[Delivered],
                Data[Estimated Delivery Date]
            [COLOR=#969696])[/COLOR],
            Data[Product] = [COLOR=#0070ff]EARLIER[/COLOR][COLOR=#969696] ([/COLOR] Data[Product] [COLOR=#969696])[/COLOR]
                && Data[Delivered] = [COLOR=#d93124]"No"[/COLOR]
        [COLOR=#969696])[/COLOR],
        Data[Estimated Delivery Date], 
        [COLOR=#0070ff]ASC[/COLOR]
    [COLOR=#969696])[/COLOR]
[COLOR=#969696])[/COLOR]
 
Last edited:
Upvote 0
Thanks for the formula gazpage, it works perfectly in the pivot table shown above.


I tried using it in a more complex pivot table and I had some difficulties getting the same result. I did some research and ended up replacing "VALUEs(Data[Customer name])" by "FIRSTNONBLANK(Data[Customer name],1)" in the formula and it worked.


Thanks again for the great help.
 
Upvote 0
Well, that would deal with a tie for the next delivery, assuming you are happy in the case of a tie for the first name alphabetically to be shown.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top