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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.