Reply
JohnYU
Frequent Visitor
Partially syndicated - Outbound

top n by dynamic

Dear experts,

 I have a table with three fields: sales, customer, and qty .

table struct.png

 

p_TOPN = DATATABLE (
    "index", INTEGER,
    "TOPN", STRING,
    {
        { 1,"TOP1" },
        { 2,"TOP2" },
        { 3,"TOP3" }
    })

 

rank meature value

 

rank_by = SWITCH(TRUE(),
 ISFILTERED(Sheet1[sales]),RANKX(ALL(Sheet1[sales]),[qtySum]),
ISFILTERED(Sheet1[customer]),RANKX(ALL(Sheet1[customer]),[qtySum]),
 BLANK())

 

 

 I am now able to rank sales and customer sales separately. 

I hope to dynamically switch between res1 and res2 through field parameters p_muti

 

p_muti = {
    ("sales", NAMEOF('Sheet1'[sales]), 0),
    ("customer", NAMEOF('Sheet1'[customer]), 1)
}

 

 

 

 

TOP_dynam =
var n = SELECTEDVALUE('p_TOPN'[index])
var tab1 = ADDCOLUMNS( DISTINCT('Sheet1'[sales]),"rank",[rank_by],"qtySum",[qtySum])
var tab2 = ADDCOLUMNS( DISTINCT('Sheet1'[customer]),"rank",[rank_by],"qtySum",[qtySum])

var res1 = CALCULATE(FIRSTNONBLANK('Sheet1'[sales],'Sheet1'[sales]),FILTER(tab1,[rank]=n))
var res2 = CALCULATE(FIRSTNONBLANK('Sheet1'[customer],'Sheet1'[customer]),FILTER(tab2,[rank]=n))

return res1

 

 

 

screenshot.png

 

 

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Syndicated - Outbound

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Syndicated - Outbound

pbi file and database 

link:https://pan.baidu.com/s/1C8C4EzhcUoOz7ztuOYNKsQ
code:fllx

Syndicated - Outbound

Cannot understand anything on that website.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Syndicated - Outbound

I have updated the information above

Syndicated - Outbound

I still do not see any content in Engligh on that website.  Could you share the download link from Google Drive/One Drive please?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Syndicated - Outbound

I rarely use onedrive or google drive

Can you access this address?

pbi file 

Syndicated - Outbound

I rarely use onedrive or google drive

Can you access this address

pbi file 

avatar user

Helpful resources

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

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)