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
Anonymous
Not applicable

Ranking Top 3 Most Expensive Invoices of Top 3 most expensive Projects

Didn't find much on ranking top N for a category at a lower granularity. Here, I want to Rank Top 3 Most Expensive Invoices of Top 3 most expensive Projects/Matters.  So Invoices are at the lower granularity. I was able to write the formula for top 3 Matters, but I tried writing Top N of Top N and it came out absolutely wrong and I ended up deleting it.  Any ideas? Data is attached below in the Google Drive Link

 

https://drive.google.com/drive/folders/1Kcr3j1baRjdvUOIQb_rMt95eSaCS2Mvi?usp=sharing

2 ACCEPTED SOLUTIONS

Hi, @Anonymous 

Please check this solution, hope this will answer the question.

Top 3 Invoices in Top 3 Matters = 
VAR TOP3MAT = 
    TOPN(3,
        SUMMARIZE(
            ALL(FactInvoiceHeader[Matter Key]),
            FactInvoiceHeader[Matter Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
VAR TOP3INV = 
    TOPN(3,
        SUMMARIZE(
            ALL(FactInvoiceHeader[Invoice Header Key]),
            FactInvoiceHeader[Invoice Header Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
RETURN
    CALCULATE(
        [Total Spend X],
        TOP3INV,
        TOP3MAT
    )

 

Thanks




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

@Anonymous 

If you need to see the Top 3 Matters and the related top 3 invoices based on the amount in  Matrix,

Use this measure:

Top 3 Invoices in Top 3 Matters = 
VAR TOP3MAT = 
    TOPN(3,
        SUMMARIZE(
            ALLSELECTED(FactInvoiceHeader[Matter Key]),
            FactInvoiceHeader[Matter Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
VAR TOP3INV = 
    TOPN(3,
        SUMMARIZE(
            ALLSELECTED(FactInvoiceHeader[Invoice Header Key]),
            FactInvoiceHeader[Invoice Header Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
RETURN
    CALCULATE(
        [Total Spend X],
        TOP3MAT,
        KEEPFILTERS(TOP3INV)
    )

 
Did I answer your question? Mark my post as a solution! 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Amazing. Those were actually some of the reference material I used, was still unable to figure out a Top 3 most expensive invoices for top 3 most expensive projects and surprisingly haven't seen much material in the community on it.

Hi @Anonymous ,

 

You can try this

 

 

Rank 3 = 
IF (
    ISINSCOPE ( FactInvoiceHeader[Invoice Header Key] ),
    RANKX (
        CALCULATETABLE (
            VALUES ( FactInvoiceHeader ),
            ALLSELECTED ( FactInvoiceHeader[Invoice Header Key] )
        ),
       CALCULATE(sum(FactInvoiceHeader[Invoice Net Amount]))
    ),
    IF (
        ISINSCOPE ( FactInvoiceHeader[Matter Key] ),
        VAR CC = CALCULATE(SUM(FactInvoiceHeader[Invoice Net Amount] ) )
        RETURN
            CALCULATE (
                RANKX (
                    VALUES ( FactInvoiceHeader[Matter Key] ),
                    CALCULATE(SUM(FactInvoiceHeader[Invoice Net Amount])),
                    CC
                ),
                ALLSELECTED ()
            )
    )

 

 

 

1.jpg

 

 

Regards,

Harsh Nathani

Hi, @Anonymous 

Please check this solution, hope this will answer the question.

Top 3 Invoices in Top 3 Matters = 
VAR TOP3MAT = 
    TOPN(3,
        SUMMARIZE(
            ALL(FactInvoiceHeader[Matter Key]),
            FactInvoiceHeader[Matter Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
VAR TOP3INV = 
    TOPN(3,
        SUMMARIZE(
            ALL(FactInvoiceHeader[Invoice Header Key]),
            FactInvoiceHeader[Invoice Header Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
RETURN
    CALCULATE(
        [Total Spend X],
        TOP3INV,
        TOP3MAT
    )

 

Thanks




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hey man. When I place it into the Matrix like in the pic below, no matrix appears, I just get a spinning wheel.

 

 

@Anonymous 

 

Drop Matter key in a table and this measure. 

I will check the matrix 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Anonymous 

If you need to see the Top 3 Matters and the related top 3 invoices based on the amount in  Matrix,

Use this measure:

Top 3 Invoices in Top 3 Matters = 
VAR TOP3MAT = 
    TOPN(3,
        SUMMARIZE(
            ALLSELECTED(FactInvoiceHeader[Matter Key]),
            FactInvoiceHeader[Matter Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
VAR TOP3INV = 
    TOPN(3,
        SUMMARIZE(
            ALLSELECTED(FactInvoiceHeader[Invoice Header Key]),
            FactInvoiceHeader[Invoice Header Key],
            "Amount",[Total Spend X]
        ),[Amount],DESC
    )
RETURN
    CALCULATE(
        [Total Spend X],
        TOP3MAT,
        KEEPFILTERS(TOP3INV)
    )

 
Did I answer your question? Mark my post as a solution! 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy  when I put this into a Matrix with Matter Key at the top of the hierarchy and Invoice Header Key under, I only got blanks......I'll post a picture.

@Anonymous 

You should get this:

Fowmy_0-1594652887868.png

 

If you are satisfied with my answer, please mark it as a solution so others can easily find it.

APPRECIATE KUDOS!


Subscribe to ExcelFort and learn Power BI, Power Query and Excel

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy  thanks man worked great.

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.