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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Jlbaenlo
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
v-stephen-msft
Community Support
Community Support

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
v-stephen-msft
Community Support
Community Support

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.

Greg_Deckler
Super User
Super User

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



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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