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

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

Reply
SamErenberger
New Member

Traffic Flow - Rank and Counts

Hi all! I've got a funny question I can't quite wrap my mind around. I have a data set with a user, a date/time, and a location. I want to create an idea of traffic flow per day per user, so that I can see where they visited first, second, third, fourth, etc. Repeated visits to the same place consectively shouldn't count, but repeat visits non-consecutively should. Here's an example of what I'm trying to do, in the 'Result' column (and here's the data set): 

 

datetimeuser_idlocResult
8/21/20219:00 AMPaulSchwartz Building1
8/21/202110:00 AMJoePeterson Wing1
8/21/202110:01 AMPaulPeterson Wing2
8/21/202111:00 AMPaulCafeteria3
8/21/202111:05 AMJoeScience Lab2
8/21/202111:30 AMSallyScience Lab1
8/21/202112:00 PMJoePeterson Wing3
8/21/20211:00 PMJoeParking Garage4
8/21/20212:35 PMSallyScience Lab1
8/21/20214:00 PMSallyCafeteria2
8/21/20219:00 AMSallyPeterson Wing3
8/21/202110:00 AMPaulCafeteria3
8/21/202110:01 AMJoeParking Garage4
8/21/202111:00 AMSallyPeterson Wing3

 

I've been poking around with the RANKX and count functions, but I haven't been able to put together much. Any ideas?

 

Eventually my goal is to tie this in to a Synoptic Panel map, so that I can use a slider to see where traffic flow throughout the building goes throughout the day or based on specific user groups. 

 

Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@SamErenberger , I think you need a rank column like

 

rankx(filter(Table, [User_id] =earlier([User_id])), [date time],,asc,dense)

 

In case you do not have a date time column

create one

date time =[date] + [time]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@SamErenberger , I think you need a rank column like

 

rankx(filter(Table, [User_id] =earlier([User_id])), [date time],,asc,dense)

 

In case you do not have a date time column

create one

date time =[date] + [time]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Adding a few more comments in case anyone is looking at this topic in the future (hi future people!).

 

In order to only show non-consecutive location changes, since my original dataset will sometimes push a 'location change' that's in the same place as the previous location, I created two new columns:

 

1. repeat_row, which concatenates User ID, Location Name and the hour that they're there. It's not perfect - if someone shows up twice consecutively but over seperate hours it won't show it repeating - but it's good enough for now. 

repeat_row = [user_id] & [location_name] & hour(Traffic_Flow_Data[time])

2. Then I created a 'repeat rank' column which shows how many times repeat_row shows up. 

repeat_value = RANKX(FILTER(Traffic_Flow_Data, Traffic_Flow_Data[repeat_row]=EARLIER(Traffic_Flow_Data[repeat_row])), [event_timestamp], , asc, Dense)

Then I created a new field that concatenates user ID and date, but only if the repeat rank = 1 - meaning it's not a repeated row. 

user_date = IF([repeat_rank]="1", CONCATENATE(Traffic_Flow_Data[user_id], Traffic_Flow_Data[date]), "xxx")

now, in my new column loc_rank, it will rank only the users that show up. User 'xxx' will get ranked in the hundreds but I have filtered that row out in all of my reports. This is using @amitchandak fabulous answer from earlier.

loc_rank = RANKX(FILTER(Traffic_Flow_Data, Traffic_Flow_Data[user_date]=EARLIER(OnsiteUnnested10k[user_date])), [event_timestamp], , asc, Dense)

 

There's probably a less convoluted way to do this, and if you have one I'm all ears! But it's working ok for now so it's my current workaround 🙂 

Thank you! That works great. This also gives me a great starting point of researching more into the RANKX function! 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors