Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
prashanth0626
Frequent Visitor

Find previous record in last 30 days

I have a table with 3 rows (MobilePhone, LeadSource,CreatedDate). I am trying to create a New column which basically displays the LeadSource if exist with the same phone number in the last 30 days else use the current Lead source. Any help how do i go ahead with this? Thanks! Capture.PNG

2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

Hi @prashanth0626 

try a column

Column = 
var _findVal = CALCULATE(FIRSTNONBLANK(Table[LeadSource]), FILTER(ALL(Table), Table[MobilePhone]=EARLIER(Table[MobilePhone]) && DATEDIFF(Table[CreatedDate], Today(), DAY) <=30) )
RETURN
if(isblank(_findVal ), Table[LeadSource], _findVal )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

@prashanth0626 

try

Prev Lead Source =
var _findVal = CALCULATE(FIRSTNONBLANK('Lead'[LeadSource],1), FILTER(ALL('Lead'), 'Lead'[MobilePhone]=EARLIER('Lead'[MobilePhone]) && DATEDIFF('Lead'[CreatedDate], EARLIER('Lead'[CreatedDate]), DAY) <=30) )

RETURN

if(isblank(_findVal ), 'Lead'[LeadSource], _findVal)    

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

Hi @prashanth0626 

try a column

Column = 
var _findVal = CALCULATE(FIRSTNONBLANK(Table[LeadSource]), FILTER(ALL(Table), Table[MobilePhone]=EARLIER(Table[MobilePhone]) && DATEDIFF(Table[CreatedDate], Today(), DAY) <=30) )
RETURN
if(isblank(_findVal ), Table[LeadSource], _findVal )

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

How do i ammend it if i want the Leadsource for last 30 days from the CreatedDate?

@prashanth0626 

try

Prev Lead Source =
var _findVal = CALCULATE(FIRSTNONBLANK('Lead'[LeadSource],1), FILTER(ALL('Lead'), 'Lead'[MobilePhone]=EARLIER('Lead'[MobilePhone]) && DATEDIFF('Lead'[CreatedDate], EARLIER('Lead'[CreatedDate]), DAY) <=30) )

RETURN

if(isblank(_findVal ), 'Lead'[LeadSource], _findVal)    

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

That actually worked! Thanks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.