Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
when i use this formula it goes on loading and takes lot of time to show output, how do i solve this problem so it loads faster
Hi,
Thanks for the solution grazitti_sapna , Kedar_Pande and dharmendars007 offered, and i want to offer some more information for user to refer to.
hello @Hemant_Jaiswar , based on your descroption, you can try the following measure.
Ranking =
VAR _topCategory =
RANKX (
ALLSELECTED ( dwdim_customer[CustomerName] ),
-- Remove context for CustomerName
CALCULATE (
[CY #Value NOS],
removefilter ( Dim_Date[Date] )
),
,
-- No tie-breaking expression
DESC -- Rank in descending order for top N
)
VAR _bottomCategory =
RANKX (
ALLSELECTED ( dwdim_customer[CustomerName] ),
-- Remove context for CustomerName
CALCULATE (
[CY #Value NOS],
removefilter ( Dim_Date[Date] )
),
,
-- No tie-breaking expression
ASC -- Rank in ascending order for bottom N
)
VAR _ranking =
IF (
SELECTEDVALUE ( 'Top OR Bottom'[Value] ) = "Top",
_topCategory,
_bottomCategory
)
VAR _TOPN =
SELECTEDVALUE ( 'Top N Parameter'[Top N Parameter], 5 ) -- Use the parameter value (default to 5 if not selected)
RETURN
IF (
_ranking <= _TOPN,
-- Check if the rank is within the top N or bottom N range
[CY #Value NOS],
BLANK () -- Return the measure if within rank
)
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Could you share some data to work with and show the expected result. Let's see if there is some other way to solve the question. Share a small sample dataset just so that i can focus on drafting a different solution. You may then plug in your actual data to test the performance of the measure.
Hi @Hemant_Jaiswar,
The provided ranking formula has performance issues because it calculates ranks across the entire dataset using the RANKX function, and it performs multiple context manipulations in both _topCategory and _bottomCategory. Optimizing this requires reducing the dataset size processed and avoiding unnecessary context modifications. Here's how you can improve the formula for better performance:
Optimized Formula
Ranking =
VAR _selectedRankingType = SELECTEDVALUE('Top OR Bottom'[Value], "Top")
VAR _topN = SELECTEDVALUE('Top N Parameter'[Top N Parameter], 5) -- Default to 5 if not selected
RETURN
IF (
_selectedRankingType = "Top",
CALCULATE(
[CY #Value NOS],
TOPN(_topN, ALL(dwdim_customer[CustomerName]), [CY #Value NOS], DESC)
),
CALCULATE(
[CY #Value NOS],
TOPN(_topN, ALL(dwdim_customer[CustomerName]), [CY #Value NOS], ASC)
)
)
Explanation of Changes
I hope the provided solution works for you
If I have resolved your question, please consider marking my post as a solution. Thank you!
A kudos is always appreciated—it helps acknowledge the effort and keeps the community thriving.
To improve the performance of your DAX measure, avoid recalculating the same measure multiple times. Store the result of [CY #Value NOS] in a variable, and use ALLSELECTED instead of ALL for the RANKX function to respect any filters. This will reduce the data being processed and improve speed. Additionally, consider pre-aggregating your data or using summary tables to avoid heavy computations during runtime.
Hello @Hemant_Jaiswar ,
Instead of removing all context with ALL(dwdim_customer[CustomerName]), consider using ALLSELECTED(). This keeps the context of other filters, which can significantly reduce the number of calculations.
VAR _topCategory =
RANKX(
ALLSELECTED(dwdim_customer[CustomerName]),
CALCULATE([CY #Value NOS], ALL(Dim_Date[Date])),,DESC)
If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!
Thank You
Dharmendar S
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
78 | |
76 | |
53 | |
37 | |
31 |
User | Count |
---|---|
101 | |
56 | |
51 | |
45 | |
40 |