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

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.

Reply
NW953
Frequent Visitor

TOPN with variable for N_Value

I have software usage data and depending of the software type we want to assign the TOPN users to discounted seats.... The number of discounted seats we have varies by software type... At the end I have a table that shows all of the pricing options and we want to select the cheapest route per user and come up with a total budget...

 

I am currently using TOPN to create a top number of users in software reports and the function works well if I enter a stactic value for the N_value, however if I try to use a function in the place the measure does not work even htough I have confirmed the right number is getting passed with the function... Is this a bug/ limitation?

 

if I replace the number 69 below with any other method of getting that number the measure stops working... I need N_value to be dynamic... what am I doing wrong here?

 

for example I want to replace 69 here with min(discounted seats)

 

My measure:

 

Forecast PDM Discount Seat Cost =
var PDM_Disc_Users =
    TOPN(69,
    ALLSELECTED(Usage[email]),
    [PDM Usage],
    DESC)
RETURN
CALCULATE(
    sumx(values(Usage[email]), min(Usage[PDM Discount Seat Cost])),
    filter(VALUES(Usage[email]), Usage[email] IN PDM_Disc_Users)
)
1 ACCEPTED SOLUTION
ahadkarimi
Solution Specialist
Solution Specialist

Hey @NW953, try this one and let me know if there is any problem.

Forecast PDM Discount Seat Cost =
var N_Value = MIN(Usage[Discounted Seats])
var PDM_Disc_Users =
TOPN(N_Value,ALLSELECTED(Usage[email]),
[PDM Usage],DESC)
RETURN
CALCULATE(sumx(
values(Usage[email]),
min(Usage[PDM Discount Seat Cost])),
filter(VALUES(Usage[email]),Usage[email] IN PDM_Disc_Users))

View solution in original post

5 REPLIES 5
SachinNandanwar
Super User
Super User

Try setting min(discounted seats) to a variable and then use it instead of 69.



Regards,
Sachin
Check out my Blog

I have tried that as well, no luck

What error do you get ?



Regards,
Sachin
Check out my Blog

I just don't get any results... version 2 uses the function, version 1 is hard coded

 

NW953_0-1723570092111.png

 

ahadkarimi
Solution Specialist
Solution Specialist

Hey @NW953, try this one and let me know if there is any problem.

Forecast PDM Discount Seat Cost =
var N_Value = MIN(Usage[Discounted Seats])
var PDM_Disc_Users =
TOPN(N_Value,ALLSELECTED(Usage[email]),
[PDM Usage],DESC)
RETURN
CALCULATE(sumx(
values(Usage[email]),
min(Usage[PDM Discount Seat Cost])),
filter(VALUES(Usage[email]),Usage[email] IN PDM_Disc_Users))

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.