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
codygros
Frequent Visitor

Determine the top occurrences of value in a specific field

Hi All,

 

I have a dataset that looks like this:

 

UserNameUserEmailActionTypePostId
user1user1@company.comPostView1
user1user1@company.comPostView2
user2user2@company.comPostComment1
user2user2@company.comPostView2
user2user2@company.comPostView3
user3user3@company.comPostView1
user4user4@company.comPostView1

 

I'm trying  to determine the top posts viewed. For example, using the data above, I would like to get the count of the PostId values and that would help me to determine the top posts being viewed. Based on the data above, I'm trying to display the top post views like this:

 

PostIdViewCount
13
22
31

 

I'm new to Power BI and can't quite figure out the best approach of getting this result. Any help is much appreciated!

 

Thanks,
CG

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @codygros ;

Here are two methods about it.

First Method:

1.add a table visual then Postid set don't summarize and useremail set count(distinct).

2.set fiter on this visual. add ActionType then set Postview.

vyalanwumsft_0-1643780719481.png

Method 2:

1.create a measure.

Measure = CALCULATE(DISTINCTCOUNT('Table'[UserEmail]),FILTER(ALLSELECTED('Table'),[PostId]=MAX([PostId])&&[ActionType]="PostView"))

The final output is shown below:

vyalanwumsft_1-1643780761882.png
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @codygros ;

Here are two methods about it.

First Method:

1.add a table visual then Postid set don't summarize and useremail set count(distinct).

2.set fiter on this visual. add ActionType then set Postview.

vyalanwumsft_0-1643780719481.png

Method 2:

1.create a measure.

Measure = CALCULATE(DISTINCTCOUNT('Table'[UserEmail]),FILTER(ALLSELECTED('Table'),[PostId]=MAX([PostId])&&[ActionType]="PostView"))

The final output is shown below:

vyalanwumsft_1-1643780761882.png
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@codygros , Create a measure like

Top 1= calculate(max(Table[PostId]),TOPN(4,allselected(table[PostId]),calculate(count(Table[PostId])),DESC), values(table[PostId]))

@amitchandak ,

 

Thanks for the response. I created a measure with the info that you provided and it is just returning a number. In my environment it is returned 35. Not sure if that is what you were expecting based on the code that you provided but I am looking to return one record for each PostId found in the table with the count of how many rows have that PostId value.  

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.