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
ropathak
Employee
Employee

Populate column for all rows that meet condition in one row

New to DAX. Whenever UserType='New', I need to flag all rows for that userID that have a Timestamp within 10 hours of the original Timestamp when the User was 'New'. If the Timestamp goes beyond 10 hours from the last TS the user was still new, flag those rows as "Returning". 

 

UserIDTimestampUserTypeUserIdentity (DESIRED COLUMN)
A2019-03-02 03:20:00NewNew
A2019-03-02 05:20:15ReturningNew
A2019-03-015 05:24:09ReturningReturning
B2020-01-13 09:34:09NewNew
B2020-04-01 12:09:34NewNew
1 REPLY 1
camargos88
Community Champion
Community Champion

Hi @ropathak ,

 

Try this code:

 

Column =
VAR _userID = 'Table (2)'[UserID]
VAR _min = CALCULATE(MIN('Table (2)'[Timestamp]); FILTER(ALL('Table (2)'); 'Table (2)'[UserID] = _userID && 'Table (2)'[UserType] = "New"))
VAR _date = 'Table (2)'[Timestamp]

RETURN IF(DATEDIFF(_min; _date; HOUR) <= 10; "New";

IF(DATEDIFF(CALCULATE(MAX('Table (2)'[Timestamp]); FILTER(ALL('Table (2)'); 'Table (2)'[UserID] = _userID && 'Table (2)'[UserType] = "New")); 'Table (2)'[Timestamp]; HOUR) > 10; "Returning"; "New"))
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



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