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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
siumui
Helper I
Helper I

Need help with selecting 150 records with 2 conditions

Hello,

 

I'm very new to PowerBI Desktop.  How do I select 150 records with two conditions?  If it's in SQL, it would be like this below:

 

SELECT TOP(150)*

FROM dbo.CUSTOMER

WHERE BATCHREF = "DRM" AND SAMPLE = "No"

 

I play around with TOPN but I don't know how to add conditions.  Please help.  

 

Thank you

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @siumui ,

You can create a calculated table like this:

Table =
TOPN (
    5,
    FILTER (
        ALL ( CUSTOMER ),
        'CUSTOMER'[BARCHREF] = "DRM"
            && 'CUSTOMER'[SAMPLE] = "No"
    ),
    'CUSTOMER'[ID], ASC
)

topn.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
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

4 REPLIES 4
v-yingjl
Community Support
Community Support

Hi @siumui ,

You can create a calculated table like this:

Table =
TOPN (
    5,
    FILTER (
        ALL ( CUSTOMER ),
        'CUSTOMER'[BARCHREF] = "DRM"
            && 'CUSTOMER'[SAMPLE] = "No"
    ),
    'CUSTOMER'[ID], ASC
)

topn.png

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yingjl 

I tried the codes.  It works awesome!!!  Thank you for all your help!!  🙏

amitchandak
Super User
Super User

@siumui ,first create a  measure

 

measure=calculate(countrows(filter(CUSTOMER,CUSTOMER[BATCHREF] = "DRM" && CUSTOMER[SAMPLE] = "No")))

 

then try TOPN

Top 10  Rank = CALCULATE([measure],TOPN(10,all(CUSTOMER[CUSTOMER Id]),[measure],DESC),VALUES(CUSTOMER[CUSTOMER Id]))

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

Hi @amitchandak 

 

I follow your instructions and create a measure in report Modeling by choose "New measure".  Then I go to the Data, click on Table Tools and select "New table" then I entered the code you have written for TOPN in the formula bar.  It gives me the error "The expresion specified in the query is not valid table expression."  It doesn't tell me where/what.  Please help.

 

Thank you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.