Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
Hi: I am trying to create a dynamic topn dax measure which will show top variances (actual against budget) for both under and over spend. The selection of number of top variances will be controlled through the slicer. In the link below where the data model has two dimension tables (cost centre and account hierarchy). First I would like to achieve topn (e.g 3) analysis based on cost centre tbl dimension showing top 3 over budget and top 3 under budget. After achieving that, is it possible to include what are top accounts contributing the variances (from the account hierarchy dimension). Any assistance would be greatly appreciated. Thanks
https://www.dropbox.com/s/wl8mf77fawg4k2w/Topn.pbix?dl=0
Hi @powerinM ,
We can create a What if parameter in your scenario.
Then we can update your formula as below.
TopVar Analysis2 =
IF (
ISINSCOPE ( 'Cost Centre Ranking'[Ranking group] ),
VAR NumOfCC = Parameter[Parameter Value]
VAR RankingGroup =
SELECTEDVALUE ( 'Cost Centre Ranking'[Ranking group] )
VAR TopCostCentre =
TOPN ( NumOfCC, ALLSELECTED ( 'Cost Centre Ranking' ), [YTD Variance] )
RETURN
SWITCH (
RankingGroup,
"Over/Under Budget Cost Centre", CALCULATE ( [YTD Variance], KEEPFILTERS ( TopCostCentre ) ),
"Other", IF (
NOT ISINSCOPE ( 'Cost Centre Ranking'[Ranking CostCentre] ),
VAR TopAmount =
CALCULATE ( [YTD Variance], TopCostCentre )
VAR AllAmount =
CALCULATE ( [YTD Variance], ALLSELECTED ( 'Cost Centre Ranking' ) )
VAR OtherAmt = AllAmount - TopAmount
RETURN
OtherAmt
)
),
[YTD Variance]
)
Thanks for your reply. Sorry I dont think the idea of using what-if parameter sits well with topn analysis. I want to acheive the topn analysis through dax measure which is goiing to show not only top over spend cost centres against budget but also top under spend against budget depends on the number selection. After that bringing in account hierarchy dimension into the analysis.
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 60 | |
| 46 | |
| 30 | |
| 24 | |
| 23 |
| User | Count |
|---|---|
| 144 | |
| 106 | |
| 64 | |
| 38 | |
| 31 |