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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Drew89
New Member

Measure for labeling items part of 80% of cumulative total quantity sold

I'm having trouble writing a measure to flag items that are part of 80% of cumulative total of quantity sold.

 

Some background information...I work for a manufacturer that acts as a supplier to distributors.  We have around 30,000 items that we offer to distributors.  The items have our item number (parent product) and have our distributor's item number (child product).  I've been asked to find the distributors that sell our items that are not selling as well as other distributors who sell the same product.  

 

For example, we offer "Product A" to 15 different disributors and in the table below you can see there are 2-3 distributors that sell a large amount of the product and the remaining 12 distributors are quite a bit lower. 

 

Parent ProductChild ProductDistributorSales AmountSales Quantity
Product AProduct A1Distributor 1538269.14458
Product AProduct A3Distributor 3644912.62444
Product AProduct A5Distributor 5240091.6164
Product AProduct A7Distributor 786204.8268
Product AProduct A9Distributor 949950.7438
Product AProduct A11Distributor 1125497.1721
Product AProduct A13Distributor 1321104.416
Product AProduct A14Distributor 1413144.0711
Product AProduct A15Distributor 1510468.038
Product AProduct A10Distributor 102949.52
Product AProduct A12Distributor 122190.342
Product AProduct A8Distributor 81708.841
Product AProduct A2Distributor 200
Product AProduct A4Distributor 400
Product AProduct A6Distributor 600

 

The company prefers to analyze things by quantity sold rather than sales dollars.

 

I'm not sure the best way to analyze this data but my idea is to take the cumulative total quantity sold and find the number of distributors that make up 80% of the total quantity sold and categorize them as "A" and the rest as "B" (this rank could be called Distributor Support Rank).  This would allow users to focus on the "B" items and find out why sales are lower for those distributors.

 

With that idea in mind, the target visual would be a table that has Parent Product, Child Product, Distributor, Sales Amount, Sales Quantity, and Distributor Support Rank (see the belowo table for the visual).  The Qty Sold Rank and Qty Sold Cumulative Pct columns would just be helper measures to help calculate the Distributor Support Rank and are not required for displaying in the visual.

 

Parent ProductChild ProductDistributorSales AmountSales QuantityQty Sold RankQty Sold Cumulative PctDistributor Support Rank
Product AProduct A1Distributor 1538269.1445810.371451744A
Product AProduct A3Distributor 3644912.6244420.731549067A
Product AProduct A5Distributor 5240091.616430.864557989B
Product AProduct A7Distributor 786204.826840.919708029B
Product AProduct A9Distributor 949950.743850.95052717B
Product AProduct A11Distributor 1125497.172160.9675588B
Product AProduct A13Distributor 1321104.41670.98053528B
Product AProduct A14Distributor 1413144.071180.98945661B
Product AProduct A15Distributor 1510468.03890.99594485B
Product AProduct A10Distributor 102949.52100.99756691B
Product AProduct A12Distributor 122190.342110.99918897B
Product AProduct A8Distributor 81708.841121B
Product AProduct A2Distributor 200131B
Product AProduct A4Distributor 400141B
Product AProduct A6Distributor 600151B

 

I'm having trouble authoring the measures to calculate the Qty Sold Rank, Qty Sold Cumulative Pct, and the Distributor Support Rank.

 

Below is my attempt at the Qty Sold Rank measure.  The "Item[No_]" field is the Child Product field.  I can't attempt to write the other measures until this one is working.

 

Drew89_0-1714653999684.png

 

Any help would be appreciated, thanks!

1 ACCEPTED SOLUTION

Hi, @Drew89 

Thank you very much for your reply. Maybe you can try the earlier. Here are the DAX expressions:

EVALUATE
VAR _summary =
    SUMMARIZECOLUMNS (
        'Table'[Parent Product],
        'Table'[Child Product],
        "sales amount", SUMX ( 'Table', 'Table'[Sales Amount] ),
        "sales Qty", SUMX ( 'Table', 'Table'[Sales Quantity] )
    )
VAR _addrank =
    ADDCOLUMNS ( _summary, "rank", RANKX ( _summary, [sales Qty],, DESC, DENSE ) )
VAR _rollingtotal =
    ADDCOLUMNS (
        _addrank,
        "QTY RT", SUMX ( FILTER ( _addrank, [rank] <= EARLIER ( [rank] ) ), [sales amount] )
    )
RETURN
    _rollingtotal

Here are the results:

vjianpengmsft_0-1715238489473.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng 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-jianpeng-msft
Community Support
Community Support

Hi, @Drew89 

Based on your description, I first created an Index column in Power Query, as shown in the following image:

vjianpengmsft_0-1714717951445.png

I use the following DAX expression to classify distributors:

MEASURE = 
VAR _table =
    SUMMARIZE (
        'Table',
        'Table'[Parent Product],
        'Table'[Child Product],
        'Table'[Sales Amount],
        'Table'[Sales Quantity],
        'Table'[Index],
        'Table'[Distributor],
        "columns",
            VAR _total_quantity =
                CALCULATE ( SUM ( 'Table'[Sales Quantity] ), ALL ( 'Table' ) )
            VAR _cumulitive_quantity =
                CALCULATE (
                    SUM ( 'Table'[Sales Quantity] ),
                    FILTER ( ALL ( 'Table' ), 'Table'[Index] <= EARLIER ( 'Table'[Index] ) )
                )
            RETURN
                DIVIDE ( _cumulitive_quantity, _total_quantity )
    )
RETURN
    IF(ISINSCOPE('Table'[Parent Product]),IF ( MAXX ( _table, [columns] ) <= 0.8, "A", "B" ))

The results are as follows:

vjianpengmsft_1-1714718053615.png

I've uploaded the PBIX file I used this time below.

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

I have the query to get the rank working in Dax Studio but I can't seem to use the rank to help calculate the rolling total.

 

Below is my query for coming up with the rank by the Sales Qty.

 

Quantity Rank - WorkingQuantity Rank - Working

 

Below is the query extended to compute the rolling total but I'm getting the error "OrderBy column 'QtyRank' could not be resolved."  I've not been succcessful in finding out how to fix this issue.

 

Quantity Rolling Total - Not WorkingQuantity Rolling Total - Not Working

Hi, @Drew89 

Thank you very much for your reply. Maybe you can try the earlier. Here are the DAX expressions:

EVALUATE
VAR _summary =
    SUMMARIZECOLUMNS (
        'Table'[Parent Product],
        'Table'[Child Product],
        "sales amount", SUMX ( 'Table', 'Table'[Sales Amount] ),
        "sales Qty", SUMX ( 'Table', 'Table'[Sales Quantity] )
    )
VAR _addrank =
    ADDCOLUMNS ( _summary, "rank", RANKX ( _summary, [sales Qty],, DESC, DENSE ) )
VAR _rollingtotal =
    ADDCOLUMNS (
        _addrank,
        "QTY RT", SUMX ( FILTER ( _addrank, [rank] <= EARLIER ( [rank] ) ), [sales amount] )
    )
RETURN
    _rollingtotal

Here are the results:

vjianpengmsft_0-1715238489473.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Thank you, this does look like it will work however I need the index/ranking to by calculated dynamically in DAX because I have multiple years of data and the ranking can change depending on the dates selected in slicers or filters.

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.