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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register 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?


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.