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
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


@ 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!:
The Definitive Guide to Power Query (M)

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


@ 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!:
The Definitive Guide to Power Query (M)

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
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