cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

TOP N issue

Hi, I have a visual "Table like" containing 

Product-Country, Sales, Switch, KPI1 (all those fields are coming from 1 table called SFA_BIAS)

Siwtch is a value = -1 or 1

and 1 filter applied on the visual on Switch (et's say 1) 

When I apply the TOPN 10 on Product-Country field based on Sales, I would expect to get the Top 10 Product-country based on Sales having Switch  = 1

the table shows no records, as if the TOPN 10 would apply on the full data behind (as the top 10 Product-Country sales without filtering have a switch = -1)

 

I have also tried with a Rank

RankSales = RANKX(
ALLSELECTED(SFA_BIAS),
CALCULATE(SUM(SFA_BIAS[SALES]))
)
The RankSales applies well to my selection
but when I filter on RankSales <=10 the table does not show me records
 
Could you please help me to understand what I am doing wrong,
 
Many thanks for your help,
JL

 

1 ACCEPTED SOLUTION
Microsoft
Microsoft

Hi @Jlbaenlo ,

 

My sample data is this.

Product-CountrySalesSwitchKPI1

JP111
JP1012
CN313
CN414
USA1215
USA1516
UK717
UK818
JP919
JP4110
CN111
CN1612
USA313
USA1514
UK1815
UK916
UK5-17
JP6-18
JP1-19
CN2-110
CN3-11
USA4-12
USA8-13
UK8-11
UK7-12
JP2-13
JP1-14
CN3-15
CN6-16
USA5-17
USA1-18
UK9-19
UK9-110

 

You could try to create a measure.This measure is to sort switch=1 and switch=-1 respectively.

 

 

Measure =
VAR ran =
    RANKX (
        FILTER ( ALL ( 'SFA_BIAS' ), 'SFA_BIAS'[Switch] = MAX ( 'SFA_BIAS'[Switch] ) ),
        CALCULATE ( MAX ( 'SFA_BIAS'[Sales] ) ),
        ,
        ASC,
        SKIP
    )
RETURN
    IF ( ran <= 10, 1, 0 )

 

 

 

Put the measure into Filters and set it.

1.png

 

The result is this.

12.png13.png

 

 

You can check more details form here.

 

Best Regards,

Stephen Tao

 

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
Microsoft
Microsoft

Hi @Jlbaenlo ,

 

My sample data is this.

Product-CountrySalesSwitchKPI1

JP111
JP1012
CN313
CN414
USA1215
USA1516
UK717
UK818
JP919
JP4110
CN111
CN1612
USA313
USA1514
UK1815
UK916
UK5-17
JP6-18
JP1-19
CN2-110
CN3-11
USA4-12
USA8-13
UK8-11
UK7-12
JP2-13
JP1-14
CN3-15
CN6-16
USA5-17
USA1-18
UK9-19
UK9-110

 

You could try to create a measure.This measure is to sort switch=1 and switch=-1 respectively.

 

 

Measure =
VAR ran =
    RANKX (
        FILTER ( ALL ( 'SFA_BIAS' ), 'SFA_BIAS'[Switch] = MAX ( 'SFA_BIAS'[Switch] ) ),
        CALCULATE ( MAX ( 'SFA_BIAS'[Sales] ) ),
        ,
        ASC,
        SKIP
    )
RETURN
    IF ( ran <= 10, 1, 0 )

 

 

 

Put the measure into Filters and set it.

1.png

 

The result is this.

12.png13.png

 

 

You can check more details form here.

 

Best Regards,

Stephen Tao

 

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

Super User IV
Super User IV

@Jlbaenlo - Sorry, having trouble following, can you post sample data as text and expected output?


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
secondImage

Experience what’s next for Power BI

Join us for an in-depth look at the new Power BI features and capabilities at the free Microsoft Business Applications Launch Event.

secondImage

Power BI Women

Join our monthly meetings and learning sessions.

secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors