cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Victor_V
Frequent Visitor

FIRSTNONBLANK by Date and ID

Hey all,

 

I'm currently working on a report for our marketing automation campaigns. I want to figure out on which campaign the most people start with their journey. The way my table is made up is like this,

 

DateUserIDCampaign
01/01/2019AZ
08/01/2019AY
04/01/2019BY
06/01/2019BX

 

So in the case above user A starts the journey with campaign Z and user B starts with campaign Y. I tried to use the following formula to extract the first interaction: 

 

 

FirstInteraction = CALCULATE(FIRSTNONBLANK(Table[Campaign], 1), ALLEXCEPT(Table, Table[UserID]))

 

 

The problem is that this then returns campaign Y for user A and campaign X for user B, because it seems to look at the alphabetical order and not the date order in which they occured. I read that DAX apparently doesn't know the order in which your data is sorted.

Is there a way to alter the formula above (or a new one) so DAX knows to look for the earliest date of each User ID and return the campaign associated with it?

2 REPLIES 2
Anonymous
Not applicable

@Victor_V Please use below measure

Measure = 
VAR _latestdate = CALCULATE(MIN('Table'[Date]),ALLEXCEPT('Table','Table'[UserID]))
RETURN CALCULATE(FIRSTNONBLANK('Table'[Campaign],TRUE()),FILTER(ALLEXCEPT('Table','Table'[UserID]),'Table'[Date]=_latestdate))

@Anonymous It worked! Thanks a lot!

Helpful resources

Announcements
Join Arun Ulag at MPPC23

Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors