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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Patv
Helper II
Helper II

Dense_Rank function in Power BI query (DAX)

Hello, 

I have a below query in oracle db and I want to replicate dense_rank functionality in power bi that returns same result in oracle but I don't know DAX much and still learning so posting question here.  I want to create a measure in Power BI that is exaclty same as below hilighted oracle query.  Attached is oracle sql and result of query for reference.

Could some one please help me here? Thank you in advance and appreciate your help!.

 

 

select
a12.YEAR_ID YEAR_ID,
a12.MONTH_ID MONTH_ID,
a13.MONTH_NAME MONTH_DESC,
(Max(a11.ENH_ACTIVE_COUNT) Keep (dense_rank Last order by a11.DATE_ID asc) + Max(a11.HELP_ACTIVE_COUNT) Keep (dense_rank Last order by a11.DATE_ID asc)) Total,
Max(a11.ENH_ACTIVE_COUNT) Keep (dense_rank Last order by a11.DATE_ID asc) Enhanced_Count,
Max(a11.HELP_ACTIVE_COUNT) Keep (dense_rank Last order by a11.DATE_ID asc) Help_Count
from PSR_FACTS a11
join RPT_PMATT_DEV.TIME_DIMENSION_DAY a12
on (a11.DATE_ID = a12.DATE_ID)
join TIME_DIMENSION_MONTH a13
on (a12.MONTH_ID = a13.MONTH_ID)
join TIME_DIMENSION_YEAR a14
on (a12.YEAR_ID = a14.YEAR_ID)
where a12.YEAR_ID in (2021,2022)
group by a12.MONTH_ID,
a13.MONTH_NAME,
a12.YEAR_ID,
a14.YEAR_DESC

pic1.png

Thank you, 

Vpat

1 ACCEPTED SOLUTION

Thank you Grag for putting greate link about RANKX. I have achieved similar result  by using Calculate  function in DAX. 

 

e.g. 

VAR_ENHA_ACTIVE_COUNT = calculate(sum(PSR_FACTS[ENH_ACTIVE_COUNT]),TIME_DIMENSION_DAY[IS_LAST_DAY_OF_MONTH] = "Y" )+calculate(sum(PSR_FACTS[ENH_ACTIVE_COUNT]),PSR_FACTS[DAY_DATE] = today(),TIME_DIMENSION_DAY[IS_LAST_DAY_OF_MONTH] = "N")

 

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Patv Not an expert on Oracle and sql syntax but the RANKX function in DAX provides a Dense option. RANKX function (DAX) - DAX | Microsoft Docs



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg. I tried to use RANKX function in Power Bi but since I am not expert in DAX, I was not able to figure it out hence I posted a question.  Let's see if someone is able to help here. Thank you for your reply.

@Patv This might help you figure out RANKX: To *Bleep* with RANKX! - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you Grag for putting greate link about RANKX. I have achieved similar result  by using Calculate  function in DAX. 

 

e.g. 

VAR_ENHA_ACTIVE_COUNT = calculate(sum(PSR_FACTS[ENH_ACTIVE_COUNT]),TIME_DIMENSION_DAY[IS_LAST_DAY_OF_MONTH] = "Y" )+calculate(sum(PSR_FACTS[ENH_ACTIVE_COUNT]),PSR_FACTS[DAY_DATE] = today(),TIME_DIMENSION_DAY[IS_LAST_DAY_OF_MONTH] = "N")

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.