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
jl02
Frequent Visitor

IF row meets conditions then return value from a previous row.

Hello,

 

I currently have data that looks like this:

Date/TimeAgent NamePhone NumberRunning CountDepartmentIsFirstFirstDepartment
1/1/2021 3:00 PMAgent A12345678901Department XDepartment X 
1/2/2021 4:00 PMAgent B09876543211Department YDepartment Y 
1/3/2021 8:00 AMAgent C12345678902Department YDuplicateDepartment X
1/10/2021 10:00 AMAgent D09876543212Department XDuplicateDepartment Y
1/13/2021 5:00 PMAgent E56789012341Department XDepartment X 

 

What I want to do is if "IsFirst" = Duplicate, then I want to find when that phone number first occured and return that department that first took the call.  My "FirstDepartment" is the column I am trying to make. However, I have been unable to obtain those desired results.

3 REPLIES 3
lbendlin
Super User
Super User

You don't really need the "Duplicate" check but you can add that if you want.

First Dept := 
var d = SELECTEDVALUE(Calls[Date/Time])
var pd = CALCULATE(max(Calls[Date/Time]),ALLEXCEPT(Calls,Calls[Phone Number]),Calls[Date/Time]<d)
var pdept = CALCULATE(max(Calls[Department]),ALLEXCEPT(Calls,Calls[Phone Number]),Calls[Date/Time]=pd)
return pdept
lbendlin
Super User
Super User

Can you guarantee that your Date/Time column has unique values and can be used for the sorting? 

jl02
Frequent Visitor

Yes, They go down to the micro-second.

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.