Return first name on a day - power pivot

atkach123

New Member
Joined
Mar 23, 2016
Messages
8
Hi,

I'm looking for a formula within PowerPivot that will allow me to create a column where the result is the first name on that day. Please refer to the link below for an example:

Imagezilla.net - Adult Image Host, Non-Adult Image Hosting

In the example, on 9/4/2015 (highlighted), this person was at two cities on that day, Whitby and Oshawa. However, they were at Whitby first, as can be seen by the "Time" column (1:00 pm vs. 2:00 pm). What I want my result column "First city on day" to return is the first city that this person was in on the day, which in this case would be Whitby.


Thanks for the help!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,
To calculate "First city on day" in a calculated column here's one way (change 'Data' to your actual table name):
Code:
=
CALCULATE (
    [COLOR=#ff0000][B]VALUES ( Data[City name] )[/B][/COLOR],
    CALCULATETABLE (
        FIRSTNONBLANK ( Data[Time], 0 ),
        ALLEXCEPT ( Data, Data[Day] )
    ),
    ALLEXCEPT ( Data, Data[Day] )
)

The part in red will cause an error if there are multiple cities at the earliest time on a given day.

If that matters, uou could replace it with say
IF ( HASONEVALUE ( Data[City name] ), VALUES ( Data[City name] ) )
or
FIRSTNONBLANK( Data[City name], 0 )

depending how you want this case handled.
 
Upvote 0
Thanks, Ozeroth - worked like a charm! Had to implement your suggestion of replacing "VALUES ( Data[City name] )" with "FIRSTNONBLANK( Data[City name], 0 )" because it was returning some blanks (multiple cities at earliest time).

I think my overall issue was figuring out how to get CALCULATE to return a text string but you figured it out for me, so thanks again!


Adam
 
Upvote 0

Forum statistics

Threads
1,224,163
Messages
6,176,789
Members
452,743
Latest member
Unique65

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