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:

ProductCustomer nameDeliveredEstimated delivery date
TVSusanYes03/15/18
TVMaryYes04/15/18
TVJohnNo06/15/18
TVDavidNo07/15/18
ComputerAndrewYes04/20/18
ComputerShannonYes05/20/18
ComputerAnnaNo06/20/18
ComputerLukeNo07/20/18

<tbody>
</tbody>

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:

ProductCustomer nameDeliveredEstimated delivery dateNext customer to receive the product
TVSusanYes03/15/18John
TVMaryYes04/15/18John
TVJohnNo06/15/18John
TVDavidNo07/15/18John
ComputerAndrewYes04/20/18Anna
ComputerShannonYes05/20/18Anna
ComputerAnnaNo06/20/18Anna
ComputerLukeNo07/20/18Anna

<tbody>
</tbody>


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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

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