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
amirabedhiafi
Impactful Individual
Impactful Individual

Get TOP 10 most commented videos by period

I have the following query to calculate the TOP 10 commented videos for a specific month and year  : 

SELECT TOP 10 videoId
,COUNT(commentId) AS CountComments FROM dbo.VideoComments
WHERE MONTH(publishedAt)=12
AND YEAR(publishedAt)=2020
GROUP BY
videoId
,MONTH(publishedAt)
ORDER BY countcomments DESC

 

I want to implement the same logic using DAX  where Month and Year are filters.

 

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@amirabedhiafi , you can use TOPN for that

Better to one field month year , assume you have measure -CountComments 

 

Top 10 City Rank = CALCULATE([CountComments ],TOPN(10,all(Table[Month Year]),[CountComments ],DESC),VALUES(Table[Month Year))

 

TOPN -https://www.youtube.com/watch?v=QIVEFp-QiOk

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@amirabedhiafi , you can use TOPN for that

Better to one field month year , assume you have measure -CountComments 

 

Top 10 City Rank = CALCULATE([CountComments ],TOPN(10,all(Table[Month Year]),[CountComments ],DESC),VALUES(Table[Month Year))

 

TOPN -https://www.youtube.com/watch?v=QIVEFp-QiOk

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

vanessafvg
Super User
Super User

are you table to provide some sample data?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

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.