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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
abc_777
Post Prodigy
Post Prodigy

hi

Hi,

 

How can i make a measure to find buttom N items

I know in power bi filter pane there is TOPN drop down and change and select buttom option but i want measure rather this pre filed selection as i can not use cell element to make data bar colour 

 

please help me  creating button N DAX measure

 

thanks

1 ACCEPTED SOLUTION

Sure! Just create a new measure using the same code and change the expression in the RANKX code from ASC to DESC (and do the same if you are using the [BN Sales] measure in the TOPN code: change from ASC to DESC)

TopN Sales =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        DESC
    )
VAR _RowSales =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )
VAR _BNsalesTotal =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        TOPN (
            SELECTEDVALUE ( 'Select Bottom n'[Value] ),
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            [Total Sale With VAT (Taka) (Measure)], DESC
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'bm_retail_t ssummary'[STORE_CODE] ),
        _RowSales,
        _BNsalesTotal
    )

Filter Top n rows =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        DESC
    )
RETURN
    COUNTROWS (
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )

Captura de pantalla 2022-10-29 130238.jpg

New file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

14 REPLIES 14
PaulDBrown
Community Champion
Community Champion

Do you have any sample data?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Jihwan_Kim
Super User
Super User

Hi,

Do you mean that you want to show ascending order, instead of descending order?

Please check the link down below. I hope it helps.

 

https://dax.guide/topn/

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


I want to show items that are sold lowest. so management can push them to sale

i need helo for creating this button or least N item as per sale value. can some one help me please

need measure

thanks

Hi @abc_777 ,

Please review the following links and check if they are what you want.

Bottom N in DAX Power BI

yingyinr_0-1666684345419.png

Bottom N Rank

 

If the above ones can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Best Regards

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

hi,

as per above link or measure its comes like 

 

abc_777_0-1666699411739.png

but i want like this, item name and with lowest lowest saling item quantity

 

abc_777_1-1666699461184.png

 

I did it from power bi filter pane there is TOPN drop down and change and select buttom option but i want measure rather this pre filed selection as i can not use cell element to make data bar colour 

 

thanks

can anyone has this solution?

please help

here file attached as sample for make measure Botton N

Thank you for the file. Ok, so which field do you need the bottom n for? The store? the User?....

Is the n fixed (like bottom 10) or is it to be dynamic based on a slicer?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






@abc_777 

Assuming you need this to be dynamic and that you need to show the bottom n stores by sales, you can:

Create a new unrelated table to use as the slicer to select the bottom n number using:

Select Table.jpgYou can then use this measure as a filter in the filter pane for your visuals, setting the result to greater or equal to 1:

 

Filter Bottom n rows =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        ASC
    )
RETURN
    COUNTROWS (
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )

 

or if you prefer a measure to deliver the actual sales for the bottom n, you can use:

 

BN Sales =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        ASC
    )
VAR _RowSales =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )
VAR _BNsalesTotal =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        TOPN (
            SELECTEDVALUE ( 'Select Bottom n'[Value] ),
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            [Total Sale With VAT (Taka) (Measure)], ASC
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'bm_retail_t ssummary'[STORE_CODE] ),
        _RowSales,
        _BNsalesTotal
    )

 

to get

res.gif

 

Sample file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi @PaulDBrown ,

 

you are really a genius. It works man, Thank you so much for your help

But you made me greedy with this awsome solution

 

How can I use this dynamic Bottom N measure same way for TOP N but I want to keep unrelated table only only

 

when I select 1,2,3...... from unrelated table in one PBI matrix table one for Bottom N and Other PBI matrix show TOP N

 

is it possible with one single unrelated table??

 

thanks

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sure! Just create a new measure using the same code and change the expression in the RANKX code from ASC to DESC (and do the same if you are using the [BN Sales] measure in the TOPN code: change from ASC to DESC)

TopN Sales =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        DESC
    )
VAR _RowSales =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )
VAR _BNsalesTotal =
    CALCULATE (
        [Total Sale With VAT (Taka) (Measure)],
        TOPN (
            SELECTEDVALUE ( 'Select Bottom n'[Value] ),
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            [Total Sale With VAT (Taka) (Measure)], DESC
        )
    )
RETURN
    IF (
        ISINSCOPE ( 'bm_retail_t ssummary'[STORE_CODE] ),
        _RowSales,
        _BNsalesTotal
    )

Filter Top n rows =
VAR _Rank =
    RANKX (
        FILTER (
            ALLSELECTED ( 'bm_retail_t ssummary'[STORE_CODE] ),
            NOT ISBLANK ( [Total Sale With VAT (Taka) (Measure)] )
        ),
        [Total Sale With VAT (Taka) (Measure)],
        ,
        DESC
    )
RETURN
    COUNTROWS (
        FILTER (
            VALUES ( 'bm_retail_t ssummary'[STORE_CODE] ),
            _Rank <= SELECTEDVALUE ( 'Select Bottom n'[Value] )
        )
    )

Captura de pantalla 2022-10-29 130238.jpg

New file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






great man

 

thank you so much for your time and effort and help. take care

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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