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
bo_afk
Post Patron
Post Patron

Using rank as filter

Hi,

I have a table below which shows the number of visits to a web site for each customer based on the channel. I've also created a measure to rank the channel for each customer (using RANKX).

What I want to do is count how many customers there are for each channel where rank is equal to 1.

Table with ranks:

CustomerChannelTotal visitsRank
APaid Search431
ADirect Load32
AEmail23
ANatural Search14
AReferring Sites05
BDirect Load261
BPaid Search52
BEmail03
BReferring Sites03
CPaid Search161
CDirect Load32
CNatural Search13
CReferring Sites13
DDirect Load21
DPaid Search12
EPaid Search41
EDirect Load12
EPaid Social12

Filter for where Rank = 1

CustomerChannelRank
APaid Search1
BDirect Load1
CPaid Search1
DDirect Load1
EPaid Search1

EXPECTED RESULT: Count number of customers per channel where rank = 1

ChannelCustomer Count
Paid Search3
Direct Load2

Can anyone help with how I can do this? When I tried this by putting the measure filter on the table (rank=1), only 'Paid search' appeared and I think this is because it has the highest total visits overall.

Thanks!

17 REPLIES 17
camargos88
Community Champion
Community Champion

@bo_afk ,

You just need to filter the visual:

Capture.PNG



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

Proud to be a Super User!



Hi @camargos88, thanks for your response.

I did try to filter the visual but it didnt work for me. What formula did you use for Rank?

I used the following:

Rank = RANKX(ALL(Table[Channel]),[Total visits])
where [Total visits] is a measure sum(visits)

@bo_afk ,

 

Use this measure, so you don't need to filter the visual:

_Rank Channel = 
VAR _tbl = SUMMARIZE('Table', 'Table'[Channel], 'Table'[Customer], "Rank", RANKX(FILTER(ALL('Table'), 'Table'[Customer] = EARLIER('Table'[Customer])), CALCULATE(SUM('Table'[Total visits])),, DESC))
RETURN COUNTX(FILTER(_tbl, [Rank] = 1), [_Rank])

 



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

Proud to be a Super User!



Thanks @camargos88 for your suggestion!

 

I have another column in my data, "device type", so it's possible for channel to appear on multiple rows for each customer if they browse on several devices. How do I amend the formula to take this column into account?

@bo_afk ,

 

How do you want to show this information (visual) ?



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

Proud to be a Super User!



Hi @camargos88 ,

Eventually I want to show this in a stacked column chart with customer counts as the value and 'channel' as the legend.

@bo_afk ,

 

So what role the column "device type" would play here ? 

Just trying to understand to think about the measure.



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

Proud to be a Super User!



Hi @camargos88, the issue I have is the following:

 

I am trying to rank on the Channel only and not device type. So 'direct load' has total of 2 visits for this customer and therefore it should be ranked 1 and 'paid search' should then be ranked 2 but as you see below, they're both ranked 1.

Power BI table rank.JPG

When I copied your formula (count customers with rank 1) it shows the following, which is wrong because as mentioned above, only direct load should appear here.

Power BI rank results.JPG

Any ideas?

Thanks again!

@bo_afk ,

 

Can you send me the mock data with this new column ? So I can work on this measure.



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

Proud to be a Super User!



Hi @camargos88, see below the data

 

CustomerChannelDeviceTotal visits
ADirect LoadTablet3
AEmailMobile Phone2
ANatural SearchTablet1
APaid SearchTablet43
BDirect LoadDesktop17
BDirect LoadTablet9
BPaid SearchDesktop3
BPaid SearchTablet2
CDirect LoadTablet3
CNatural SearchTablet1
CPaid SearchDesktop8
CPaid SearchTablet8
CReferring SitesTablet1
DDirect LoadMobile Phone1
DPaid SearchDesktop2
DPaid SearchMobile Phone2
DPaid SocialDesktop1
EDirect LoadDesktop1
EDirect LoadMobile Phone1
EPaid SearchMobile Phone1

@bo_afk ,

 

Please, check the attached file.



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

Proud to be a Super User!



Hi @camargos88, thanks for the file!

Numbers are still slightly off and I think this is because of customer E. As you can see below, the total number of visits for "Direct Load" for this customer is 2 (1 on mobile and 1 on desktop), but the total visits for "Paid search" is 1 (just 1 for mobile). Therefore, "Direct load" should have a rank of 1 and "Paid search" a rank of 2, but here both are ranked as 1.

 

Is theere a way to 'ignore' the device type?

 

bo_afk_0-1603898806815.png

 

@bo_afk ,

 

Direct Load has customer with 1 for customer B and E.

 

I am a little bit confused here:
"Therefore, "Direct load" should have a rank of 1 and "Paid search" a rank of 2, but here both are ranked as 1."

 

The measure gets the highest visits for each channel/customer and filter the ranking number 1.

 

What do you mean with rank of 2 ?



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

Proud to be a Super User!



@camargos88 Sorry I should say that "Paid search" shouldn't have a rank of 1 because the total number of visits for customer E through this channel is 1, whereas the total number of visits for customer E through "Direct load" is 2. Does this make sense?

bo_afk_0-1603899549990.png

@bo_afk ,

 

Check the file again, I've ignored the device type.

 



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

Proud to be a Super User!



Hi @camargos88, thanks for this!

 

Weirdly, it doesnt seem to work with my dataset and I'm not too sure why...it's still showing rank 1 for customer E for both 'direct load' and 'paid search'.

 

But I can definitely see that it's worked with the one I gave you. Maybe I need to reload my data back into my report or something. Will try to figure out what's caused this.

@bo_afk ,

 

Keep in mind that if you have the ties, the values are gonna be the same, so you need to break it.



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