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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
JamesMoody
Frequent Visitor

Return earliest non blank row by User ID

I am wanting to have a calculated column that returns '1' for the first 'User ID' against our 'Call IDs', the purpose is to determine the first agent that took one of our calls. 

At the moment I have the below measure which is working as expected but the problem i have is that it returns a '1' for blank rows if that is the earliest user ID - I am trying to work out how this measure can be changed to show '1' for the first non blank row.

 

First Agent =

VAR Call_id = 'Call Records'[Call Record ID]

 

VAR Earliest_date = CALCULATE(MIN('Call Records'[Start DateTime]),

FILTER('Call Records','Call Records'[Call Record ID]=Call_id))

 

VAR Earliest_Agent = CALCULATE(MIN('Call Records'[User ID]),

FILTER('Call Records','Call Records'[Start DateTime]=Earliest_date),
FILTER('Call Records','Call Records'[Call Record ID]=Call_id))


RETURN IF('Call Records'[Start DateTime]=Earliest_date && 'Call Records'[User ID]=Earliest_Agent,
1,BLANK())​

 

 

Here is a snapshot of the data 

Call IDUser IDStart DateTimeFirst Agent
013b5db2-f620-4fc1-9b947676b92c-c51c-4ee0-aba72023-11-27T12:35:56.06300001
013b5db2-f620-4fc1-9b947676b92c-c51c-4ee0-aba72023-11-27T12:35:57.18300001
013b5db2-f620-4fc1-9b94 2023-11-27T12:35:57.1870000 
013b5db2-f620-4fc1-9b94 2023-11-27T12:36:30.5400000 
013b5db2-f620-4fc1-9b94b0e97635-769b-439b-bbf22023-11-27T12:36:30.5430000 
017d0039-5b25-43af-acdeb0e97635-769b-439b-bbf22023-11-27T14:29:54.49000001
017d0039-5b25-43af-acdeb0e97635-769b-439b-bbf22023-11-27T14:29:55.63000001
017d0039-5b25-43af-acde 2023-11-27T14:29:55.6330000 
03b5f72e-7199-474f-94df9df610bf-d62e-4110-aad82023-11-27T09:45:52.8600000 
03b5f72e-7199-474f-94df 2023-11-27T09:45:52.85000001
03b5f72e-7199-474f-94df9df610bf-d62e-4110-aad82023-11-27T09:45:52.8600000 
0b27d03a-cf61-450d-87aa 2023-11-24T10:45:42.31000001
0b27d03a-cf61-450d-87aa 2023-11-24T10:45:42.32300001

 

Thanks

5 REPLIES 5
JamesMoody
Frequent Visitor

Hi @FreemanZ,


This seems to have solved the issue of looking at the blank rows but there are now some rows without the '1' to indicate any first 'User ID'.

 

Example:

JamesMoody_0-1701140236987.png

 

Here is another example from my data set that is also not showing anything

Call  IDUser IDStart DateTimeColumn
fd114fd1-21e3-46a8-8c808f972230-ecc7-4413-b18410/11/2023 9:24 
fd114fd1-21e3-46a8-8c80 10/11/2023 9:23 
fd114fd1-21e3-46a8-8c80 10/11/2023 9:23 
fd114fd1-21e3-46a8-8c80 10/11/2023 9:23 
fd114fd1-21e3-46a8-8c809df610bf-d62e-4110-aad810/11/2023 9:25 
fd114fd1-21e3-46a8-8c808f972230-ecc7-4413-b18410/11/2023 9:24 
fd114fd1-21e3-46a8-8c80 10/11/2023 9:23 
fd114fd1-21e3-46a8-8c808f972230-ecc7-4413-b18410/11/2023 9:24 
fd114fd1-21e3-46a8-8c800c446220-b40a-4022-bf1810/11/2023 9:23 
fd114fd1-21e3-46a8-8c808f972230-ecc7-4413-b18410/11/2023 9:25 
fd114fd1-21e3-46a8-8c808f972230-ecc7-4413-b18410/11/2023 9:25 
fd114fd1-21e3-46a8-8c809df610bf-d62e-4110-aad810/11/2023 9:27 
fd114fd1-21e3-46a8-8c809df610bf-d62e-4110-aad810/11/2023 9:25 

 

 

Apologies, I had accidentally removed some characters from the IDs

 

Here is the correct data and how I am seeing it.

 

Example.PNG

 

Data:

Call  IDUser IDStart DateTime
fd114fd1-21e3-46a8-8c80-eb57d6af18e88f972230-ecc7-4413-b184-60025d7398b710/11/2023 9:24
fd114fd1-21e3-46a8-8c80-eb57d6af18e8 10/11/2023 9:23
fd114fd1-21e3-46a8-8c80-eb57d6af18e8 10/11/2023 9:23
fd114fd1-21e3-46a8-8c80-eb57d6af18e8 10/11/2023 9:23
fd114fd1-21e3-46a8-8c80-eb57d6af18e89df610bf-d62e-4110-aad8-5010f369959410/11/2023 9:25
fd114fd1-21e3-46a8-8c80-eb57d6af18e88f972230-ecc7-4413-b184-60025d7398b710/11/2023 9:24
fd114fd1-21e3-46a8-8c80-eb57d6af18e8 10/11/2023 9:23
fd114fd1-21e3-46a8-8c80-eb57d6af18e88f972230-ecc7-4413-b184-60025d7398b710/11/2023 9:24
fd114fd1-21e3-46a8-8c80-eb57d6af18e80c446220-b40a-4022-bf18-7ae5a11fcd2310/11/2023 9:23
fd114fd1-21e3-46a8-8c80-eb57d6af18e88f972230-ecc7-4413-b184-60025d7398b710/11/2023 9:25
fd114fd1-21e3-46a8-8c80-eb57d6af18e88f972230-ecc7-4413-b184-60025d7398b710/11/2023 9:25
fd114fd1-21e3-46a8-8c80-eb57d6af18e89df610bf-d62e-4110-aad8-5010f369959410/11/2023 9:27
fd114fd1-21e3-46a8-8c80-eb57d6af18e89df610bf-d62e-4110-aad8-5010f369959410/11/2023 9:25

Hi @JamesMoody ,

 

could you also provide the expected result column directly?

like this?

column = 
VAR _startdatetime = 
MINX(
    FILTER(
        data2, 
        data2[Call ID]=EARLIER(data2[Call ID])
    ),
    data2[Start DateTime]
)
VAR _result=
IF(
    [User ID]<>BLANK() && _startdatetime = [Start Datetime],
    1
)
RETURN _result

FreemanZ_0-1701149450522.png

 

FreemanZ
Super User
Super User

hi @JamesMoody ,

 

try to add a calculated column like:

column = 
VAR _startdatetime = 
MINX(
    FILTER(
        data, 
        data[Call ID]=EARLIER(data[Call ID])
    ),
    data[Start DateTime]
)
VAR _result=
IF(
    [User ID]<>BLANK() && _startdatetime = [Start Datetime],
    1
)
RETURN _result

 

it worked like:

FreemanZ_0-1701134681015.png

 

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.