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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Dimi_2207
Helper I
Helper I

To show previous value based another column in DAX

Hello !

 

I have a big set of data and need to show in the column "Previous agent" the agent who took the previous call from the same phone number, please see the example below:

 

DatePhone numberAgentCall AttemptPrevious Agent
13-12-23 16:0211111Agent 11 
14-12-23 16:0311111Agent 22Agent 1
27-12-23 13:4911111Agent 33Agent 2
28-12-23 13:1822222Agent 31 
29-12-23 11:4922222Agent 22Agent 3
29-12-23 12:4933333Agent 2 1 
29-12-23 15:4233333Agent 12Agent 2

 

I've found solution for this, it works, but it is very slow... Almost impossible to work when i have big volumes of data (currently i have 34 000 rows).

Here is the solution i've found: 

 

Dimi_2207_0-1708181963343.png

 

Could you, please, help me with alternative in DAX that is faster ?

 

Thank you very much !

1 ACCEPTED SOLUTION

Hi,

Write this calculated column formula

Column = LOOKUPVALUE(Data[Agent],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[Phone]=EARLIER(Data[Phone])&&Data[Date]<EARLIER(Data[Date]))),Data[Phone],Data[Phone])

Hope this helps.

Ashish_Mathur_0-1708299266800.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

This should ideally be solved with a calculated column formula

Previous agent = CALCULATE(MAX(Data[Agent]),FILTER(Data,Data[Phone number]=EARLIER(Data[Phone number])&&Data[Date]<EARLIER(Data[Date])))

Hope this helps.

Ashish_Mathur_0-1708214854961.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you very much, it works great and quickly with the initial sample i've provided, where i have: Agent 1, Agent 2, Agent 3...

Actually, i have names in that column (sorry, i had to be more precise from the start!)

And, in this case, this does not work...Please, see, updated sample size.

Expectation: 

PhoneDateAgentPrevious agent
11108-11-23 08:24Kate 
11108-11-23 09:48AlexKate
11108-11-23 10:38ZaraAlex
11108-11-23 10:57MichaelZara
11108-11-23 14:36NatalyMichael
11108-11-23 15:54YohanNataly
11109-11-23 08:38SofiaYohan
11109-11-23 10:14SofiaSofia
11109-11-23 10:15RikSofia
22213-12-23 16:02Rik 
22214-12-23 16:03AmandaRik
33322-12-23 19:25Maria 
33323-12-23 18:54CyrilMaria
33323-12-23 19:01IvanCyril
22227-12-23 13:49NikolasAmanda
33328-12-23 08:56ElenaIvan

 

What Power BI shows:

Dimi_2207_0-1708246767551.png

 

Hi,

Write this calculated column formula

Column = LOOKUPVALUE(Data[Agent],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[Phone]=EARLIER(Data[Phone])&&Data[Date]<EARLIER(Data[Date]))),Data[Phone],Data[Phone])

Hope this helps.

Ashish_Mathur_0-1708299266800.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank very much !

Works perfectly

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Community Champion
Community Champion

@Dimi_2207 Try a calculated column perhaps? Generally looks like MTBF without the final step, you just want the previous value, not a difference or any calculation. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.