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
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
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.

Top Solution Authors