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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
joycewoo
Frequent Visitor

Unique Count of Invoice and Total Product Spend based on Vendor from Top 80% Spend

Dear Community,

 

I search this forum with many different keywords but still cannot get to solution yet, totally no idea how to tackle this.

The complex part is that the value should be responsive to all present filters, so calculated column cannot achieve the result, believe it has to be dynamic measures. 

 

Sample data like this:

VendorInvoiceIdDepartmentProductIdSpend Amount
Vendor AINV001Dept1Product110
Vendor AINV001Dept1Product220
Vendor AINV001Dept3Product350
Vendor AINV001Dept4Product140
Vendor AINV002Dept2Product125
Vendor AINV002Dept3Product380
Vendor AINV002Dept3Product1100
Vendor BINV003Dept1Product190
Vendor BINV003Dept1Product280
Vendor BINV003Dept3Product370
Vendor BINV003Dept4Product150
Vendor BINV004Dept2Product115
Vendor BINV004Dept1Product225
Vendor BINV004Dept3Product335
Vendor BINV004Dept3Product145
Vendor CINV005Dept1Product190
Vendor CINV005Dept1Product136
Vendor DINV006Dept1Product190
Vendor DINV006Dept1Product1150
Vendor DINV006Dept1Product115
Vendor DINV007Dept2Product235
Vendor DINV007Dept3Product320

 

Desired result:

 

Visual A is total spend amount by vendor (shows that Vendor B & Vendor A are contributed to Top 80% of spend amount).

joycewoo_6-1662395256779.png

Visual B (spend/inv count by product), C1 and C2 (inv count based on amount range) are calculated based on Top 80% Spend Vendors.

joycewoo_5-1662395156534.png

joycewoo_9-1662397007865.png

I only managed to achieve visual A, but unable get the result for visual B, C1 and C2. 

 

Any help would be very much appreciated.

Thanks in advance. 

 

 

 

 

 

 

5 REPLIES 5
joycewoo
Frequent Visitor

Try on this dax but didn't get the correct result. Can anyone helps? 

Top Invoice # =
VAR SpendByParentSupplier =
    ADDCOLUMNS (
        ALLSELECTED ( Data[Vendor]),
        "SpendAmount", [Total Spend],
        "Vendor1", Data[Vendor]
    )
VAR AllSpend =
    CALCULATE (
        [Total Spend],
        ALLSELECTED ( Data[Vendor] )
    )
VAR CumulatedPercent =
    ADDCOLUMNS (
        SpendByParentSupplier,
        "Cumulative%",
        VAR CurrentSpendAmount = [SpendAmount]
        VAR CumulatedSpend =
            FILTER (
                SpendByParentSupplier,
                [SpendAmount] >= CurrentSpendAmount
            )
        VAR CumulatedSpendAmount =
            SUMX (
                CumulatedSpend,
                [SpendAmount]
            )
        RETURN
            DIVIDE (
                CumulatedSpendAmount,
                AllSpend
            )
    )
VAR FilteredTable =
    filter( CumulatedPercent, [Cumulative%] <= 0.8)



VAR SpendbyInv =
    ADDCOLUMNS(
        ALLSELECTED ( Data[Vendor], Data[ProductId],Data[InvoiceId]),
        "SpendAmount1", [Total Spend],
        "Vendor1", Data[Vendor]
    )
VAR FilteredTable2 =
    FILTER(
        CROSSJOIN(
            SpendbyInv,
            'Range'),
            [SpendAmount1] >='Range'[Min Value] &&
                [SpendAmount1] < 'Range'[Max Value]
    )

Var JoinedTable =
        NATURALINNERJOIN(
            FilteredTable,
            FilteredTable2)

RETURN
    Calculate([Invoice Count],  KEEPFILTERS( JoinedTable ))
 
joycewoo_1-1662540761883.png

 


 

CNENFRNL
Community Champion
Community Champion

Your question is an variant of common Pareto analysis; but I'm not surprised that you can't solve it after a deep look into it. Its intricacy is way more than it appears. It's way beyond most users.

CNENFRNL_0-1662471636466.gif


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

I gather Dynamic ABC Classification from this post might be helpful but I just don't know how to fit it to my case. 
ABC classification – DAX Patterns

ddpl
Solution Sage
Solution Sage

@joycewoo ,

 

Can you enlighten us how you got Visual B ???, especially Spent Amount(Top 80% Spend Vendors) more explicitly.

joycewoo
Frequent Visitor

Hi, thanks for replying to my question. 

 

Vendors are ranked/sorted based on total spend amount, from largest total amount ranked as first to smallest. Based on the sorted vendor then calculate the cumulative percentage. Lastly, vendors with cumulative percentage from 0% up to 80% are categorised as Top 80% spend vendors. (this is what you can see from visual A).


From the sample data given above, only vendor A and B are within cumulative 80% (vendor D & C already exceeded 80% so out of scope). 

So, visual B is the total amount and invoice count by product for Top 80% spend vendors, which is vendor A and B only. This two vendors contributed 3 products (Product1, Product2 and Product3). 

 

Below is example how to get the total amount ($375) and invoice count (4 invoices) for Product1. 

joycewoo_0-1662442389602.png

I hope this helps. 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors