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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Syndicate_Admin
Administrator
Administrator

Top N with static values

Hello

I have a table of dimensions with the attributes of a product, and another table (of dimensions too) with the warehouses where it is sold.

It is required to initially generate a top of which are the products that sell the most at a general level. For the example I have a top of the 3 products that sell the most.

ProductValue
Product A$ 16,500.00
Product B$ 3,200.00
Product C$ 1,800.00
Total$ 21,500.00

Then it is necessary to generate a matrix where it is indicated of those selected products, the distribution by warehouse of the same. The following result should be obtained.

WarehouseProductValue
Warehouse 2Product A$ 10,000.00
Warehouse 3Product B$ 500.00
Warehouse 4Product C$ 100.00
Warehouse 3Product A$ 5,000.00
Warehouse 4Product B$ 1,700.00
Warehouse 5Product C$ 600.00
Warehouse 4Product A$ 1,500.00
Warehouse 5Product B$ 1,000.00
Warehouse 6Product C$ 1,100.00
Total $ 21,500.00


But at the time of calculating the matrix, the top of the products for each warehouse is appearing, and the products THAT ARE NOT in the initial filter (A, B, C) are shown. The total value IF OK, but the detail is not (products X, Y, Z should not even appear).

WarehouseProductValue
Warehouse 2Product A$ 3,800.00
Warehouse 3Product B$ 2,500.00
Warehouse 4Prodcut Z$ 589.00
Warehouse 3Product X$ 8,792.00
Warehouse 4Product Y$ 4,256.00
Warehouse 5Product A$ 2,587.00
Warehouse 4Product C$ 950.00
Warehouse 5Product B$ 671.00
Warehouse 6Prodcut Z$ 645.00
Total**Real value 24,790**$ 21,500.00

I used the functions of RANK(), TOPN to calculate the values. And when I think the calculation is going to come out, it breaks. This is the formula I used.

VALOR_INICIAL_TOP_N_ORIG = 
VAR TOP_TABLA = TOPN(3, ALLSELECTED(AUX_MARCA), [#VALOR_HECHOS_INICIAL])
VAR VALOR_TABLA = CALCULATE([#VALOR_HECHOS_INICIAL], KEEPFILTERS(TOP_TABLA))
RETURN
VALOR_TABLA

I appreciate your collaboration to solve this, since I can't find how to do it.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Syndicate_Admin ,

I created some data:

vyangliumsft_0-1643256458593.png

You can use tabs to display:

Here are the steps you can follow:

1. Create measure.

 

VALOR_INICIAL_TOP_N_ORIG =
var _Table=SUMMARIZE(ALL('Table'),'Table'[Product],"Total",SUM('Table'[Value]))
var _TOP_TABLA=TOPN(3,_Table,[Total],DESC)
return
IF(
    MAX('Table'[Product]) in SELECTCOLUMNS(_TOP_TABLA,"1",[Product]),
    1,0)

 

2. Place [VALOR_INICIAL_TOP_N_ORIG]in Filters, set is=1, apply filter.

vyangliumsft_1-1643256458596.png

3. Result:

vyangliumsft_2-1643256458597.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Syndicate_Admin ,

I created some data:

vyangliumsft_0-1643256458593.png

You can use tabs to display:

Here are the steps you can follow:

1. Create measure.

 

VALOR_INICIAL_TOP_N_ORIG =
var _Table=SUMMARIZE(ALL('Table'),'Table'[Product],"Total",SUM('Table'[Value]))
var _TOP_TABLA=TOPN(3,_Table,[Total],DESC)
return
IF(
    MAX('Table'[Product]) in SELECTCOLUMNS(_TOP_TABLA,"1",[Product]),
    1,0)

 

2. Place [VALOR_INICIAL_TOP_N_ORIG]in Filters, set is=1, apply filter.

vyangliumsft_1-1643256458596.png

3. Result:

vyangliumsft_2-1643256458597.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@Syndicate_Admin , Try like

 

Assume value in measure , Try like

 

Measure =
var _tab = TOPN(3,allselected(table[Product]),[#VALOR_HECHOS_INICIAL],Desc)
return
calculate([Value], filter(table, table[#VALOR_HECHOS_INICIAL] in _tab))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors