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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Atseaukes
Frequent Visitor

Index column based on date, multiple entries excluded based on time

Current colomns    Desired column
action iduser_iddatetime Index
2ac9756d-d46d-42ff-b759-6fb88beaf8f7111-06-1811:35:40 1
30ac92ed-8e81-4443-aed7-8261eb0a597c112-06-1820:15:18 2
8ab1ed3d-523f-4926-a4f5-a4c938e693da113-06-1816:55:40 3
a2119042-caf3-408d-8ed4-43f3ad197765212-06-1822:53:24 1
a8a95082-bc10-4d80-9333-41db49900df0212-06-1822:53:22 1
c3b7b029-4344-440f-a31c-8f54c84f1a73311-06-1815:43:11 1
666a64cf-cb1d-434a-93b5-ed49fe785218314-06-1815:43:11 2
5c3ae105-78a8-4adb-86ce-1ac670edb100315-06-1815:43:10 3
55f913f1-c14d-4824-9d27-a27bde8b93b5316-06-1815:43:09 4
cfcde4bf-cb48-46bc-a105-4f95fba50895407-06-1815:44:16 1
f1b312ae-1f09-4870-80ba-4475f7731679409-06-1822:53:22 2
5876a70a-eb01-4adf-9ff3-35fef3641148409-06-1822:53:20 2
      
The index is based on User_id per day    
If a User_id has multiple entries on the same day the index needs to be the same (see ID 2)

 

Above an example of my data. I rather new to powerbi and I cannot figure out how to exclude the multiple entries (like in ID 2) in my index.

 

The purpose is to see how active a user is in terms of the number of days since the first day of activity. 

 

Could anyone help me out how to resolve this?

1 ACCEPTED SOLUTION

Step 1:

Index =

VAR UserFirstDate = MINX(FILTER('Events Completion';'Events Completion'[user_id] = EARLIER('Events Completion'[user_id]));'Events Completion'[DateTime])
RETURN

DIVIDE (DATEDIFF(UserFirstDate ;'Events Completion'[DateTime];DAY);1)+1

 

Step 2:

Rank =
VAR d = 'Events Completion'[Index]
VAR c = 'Events Completion'[user_id]
RETURN
CALCULATE (
RANK.EQ ( d; 'Events Completion'[Index]; ASC );
FILTER ( ALL ( 'Events Completion'); 'Events Completion'[user_id] = c ))

View solution in original post

10 REPLIES 10
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi  @Atseaukes

 

You could try this calculated column which takes into account date & time

 

Column = 
VAR UserFirstDate = MINX(FILTER('Table1','Table1'[user_id] = EARLIER('Table1'[user_id])),'Table1'[date] & " " & 'Table1'[time])
RETURN DIVIDE(DATEDIFF(UserFirstDate ,'Table1'[date] & " " & 'Table1'[time],HOUR),24)+1

Can adjusted as needed


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark,

 

I used:

Index =
VAR UserFirstDate = MINX(FILTER('Events Completion';'Events Completion'[user_id] = EARLIER('Events Completion'[user_id]));'Events Completion'[date] & " " & 'Events Completion'[time])
RETURN DIVIDE(DATEDIFF(UserFirstDate ;'Events Completion'[date] & " " & 'Events Completion'[time];HOUR);24)+1

 

but somehow that didn't work. See the example hereunder.

 Voorbeeld.png

 

It gave back negative results and decimals which, in addition, are not the same for the same day... 

 

Any clue?

I made some changes:

DayOfUse = VAR UserFirstDate = MINX(FILTER('Events Completion';'Events Completion'[user_id] = EARLIER('Events Completion'[user_id]));'Events Completion'[DateTime])
RETURN DIVIDE(DATEDIFF(UserFirstDate ;'Events Completion'[DateTime];DAY);1)+1

 

But this results in the day number after first use. So startdate gives value 1. Second date is af day 10 gives value 10.

How to change the second (thirth, forth, etc) day into value 2?

 

Hi @Atseaukes

 

Is the time of day important?

 

Eg, if the first item starts at 2pm (in the afternoon) on a Monday.

 

In that case, what value would you give to an event that took place at 10am on the following Wednesday, and also to one that took place at 8pm on the same Wednesday?  

 

Do you need to track that one of those events was less than 48 hours while the other is more than 48 hours to give a different result?  Or should both have the same value because the time component is not important?

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark,

 

The time of day is not important.

 

Monday would have value 1. The following Wednesday at 10am would have value 2, just like the event at 8pm (value = 2).

ok, then does this get closer?

 

Column = 
VAR UserFirstDate = MINX(FILTER('Table1','Table1'[user_id] = EARLIER('Table1'[user_id])),'Table1'[date] )
RETURN DATEDIFF(UserFirstDate ,'Table1'[date] ,DAY)+1

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark,

 

On the subsequent days the value is correct. However, if there are more days in between, those days are added to the value. The values must be an orderly one. 

 

Like in this example (all have the same user_id):

1-06-18, 12:00 ; value 1

1-06-18, 13:00 ; value 1

2-06-18, 12:00 ; value 2

4-06-18, 12:00 ; value 3 (instead of value 4, which will be the result of the formula I posted)

Hi @Phil_Seamark,

 

Do you have any suggestions what to do else?

Maybe doable with a RANKX? 

Rank = RANKX('Events Completion';'Events Completion'[Index];;ASC;Dense)

But first it needs to be filtered by 'Events Completion'[User_ID] I guess, right?

Step 1:

Index =

VAR UserFirstDate = MINX(FILTER('Events Completion';'Events Completion'[user_id] = EARLIER('Events Completion'[user_id]));'Events Completion'[DateTime])
RETURN

DIVIDE (DATEDIFF(UserFirstDate ;'Events Completion'[DateTime];DAY);1)+1

 

Step 2:

Rank =
VAR d = 'Events Completion'[Index]
VAR c = 'Events Completion'[user_id]
RETURN
CALCULATE (
RANK.EQ ( d; 'Events Completion'[Index]; ASC );
FILTER ( ALL ( 'Events Completion'); 'Events Completion'[user_id] = c ))

Atseaukes
Frequent Visitor

Current colomns    Desired column
action iduser_iddatetime Index
2ac9756d-d46d-42ff-b759-6fb88beaf8f7111-06-1811:35:40 1
30ac92ed-8e81-4443-aed7-8261eb0a597c112-06-1820:15:18 2
8ab1ed3d-523f-4926-a4f5-a4c938e693da113-06-1816:55:40 3
a2119042-caf3-408d-8ed4-43f3ad197765212-06-1822:53:24 1
a8a95082-bc10-4d80-9333-41db49900df0212-06-1822:53:22 1
c3b7b029-4344-440f-a31c-8f54c84f1a73311-06-1815:43:11 1
666a64cf-cb1d-434a-93b5-ed49fe785218314-06-1815:43:11 2
5c3ae105-78a8-4adb-86ce-1ac670edb100315-06-1815:43:10 3
55f913f1-c14d-4824-9d27-a27bde8b93b5316-06-1815:43:09 4
cfcde4bf-cb48-46bc-a105-4f95fba50895407-06-1815:44:16 1
f1b312ae-1f09-4870-80ba-4475f7731679409-06-1822:53:22 2
5876a70a-eb01-4adf-9ff3-35fef3641148409-06-1822:53:20 2
      
The index is based on User_id per day    
If a User_id has multiple entries on the same day the index needs to be the same (see ID 2)

 

Above an example of my data. I rather new to powerbi and I cannot figure out how to exclude the multiple entries (like in ID 2) in my index.

 

The purpose is to see how active a user is in terms of the number of days since the first day of activity. 

 

Could anyone help me out how to resolve this?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.