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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
iggyvic
Frequent Visitor

Finding the share of orders containing only dynamic top n items

Hi,

 

I have a table containing the following columns:

Document No_Posting DateLine No_Sell-to Customer No_No_Location CodeQuantity
16930972020-01-11100002267896217351
16922622020-01-11100001580586916421
16922632020-01-111000024506497233851
16930982020-01-11100002494736702081
16930962020-01-11100002414284068041
16930982020-01-11200002494736808481
16922632020-01-112000024506496894851
16930982020-01-11300002494736808281
16922632020-01-113000024506499269851
16922622020-01-11300001580584250321
16922622020-01-11400001580589939621
16922622020-01-11600001580589948621
16922622020-01-11700001580589771121
16922622020-01-11800001580589017721
16922622020-01-11500001580589940122
16922622020-01-111000001580583231322
16922622020-01-11900001580583231423
16922622020-01-11200001580583275522

I found the following DAX-code online and managed to rank the items (No_) by distinct count of order (Document No_)

 

 

 

Rank =
VAR __currentCategory =
    MAX ( 'Sales Invoice Line'[No_] )
VAR __tmpTable =
    ALL ( 'Sales Invoice Line'[No_] )
VAR __tmpTable1 =
    SUMMARIZE (
        __tmpTable,
        'Sales Invoice Line'[No_],
        "__Count", COUNT ( 'Sales Invoice Line'[No_] )
    )
VAR __tmpTable2 =
    ADDCOLUMNS ( __tmpTable1, "__Rank", RANKX ( __tmpTable1, [__Count] ) )
RETURN
    MAXX (
        FILTER ( __tmpTable2, 'Sales Invoice Line'[No_] = __currentCategory ),
        [__Rank]
    )

 

 

 

The rank is updated based on a date slicer (Posting Date).

 

I would like to expand on this solution to find the share of:

1. Orders containing only one of any top n items, and

2. Orders containing several rows but only any top n items

and have the date slicers controlling these results as well. 

 

I'm thinking something along the lines of:

Date Slicer: 2021-01-01 -> 2021-12-31

Top N: 1000

Item RankNo_Distinct count of Document No_Count of 1-line order containing item
1621732647543
2691642100999
39723319001234
......  
1000670202323

And then a separate measure

% of distinct count of orders that only contain top N items

 

I tried searching but couldn't find a way to filter on the dynamic top items among the orders. Does anyone know where I could start looking or how this could be achieved? 

2 REPLIES 2
iggyvic
Frequent Visitor

Hey and thanks for getting back to me! 

 

Yes, the slicer should be used to control the data included in the calculations. Say if you select January 2022, you might get a different top (more heating related items) list of items compared to June 2021 (more barbecue related items), depending on what seasonally sells. 

 

Now of course the limited data set I pasted wasn't especially useful (sorry!) but I've taken a week's worth of data and anonymized it a bit in this .pbix: Sales.pbix

 

There it should say that:

1. 62279, 99180 and 61985 are the top (for example three) items that week (because they are the No_ contained in the largest number of distinct Document No_)

2. And that 371 of 543 of the Document No_ contain only at least one of these three top items

 

Hope that makes it clearer? Otherwise I'm happy to clarify further!

v-xiaotang
Community Support
Community Support

Hi @iggyvic 

"1. Orders containing only one of any top n items, and

2. Orders containing several rows but only any top n items"

-  Do you mean you want to use a slicer to select the modes above? And could you share the expected results according to your data? Thanks. (I'm just want to know how it displays based on your data.

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors