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
mihaistanca7
Frequent Visitor

Calculated table based on TOP 5 - return invoices for those in TOP 10

Hello

Please help me to calculate in DAX this table.

I have the intial table named "Balance" which contains all client invoices.

I must display in another table the invoices for top five clients after column "Balance", without considering account "Accoun3".

So first i must do SUM on column "Balance" than order DESC, see which are top 5, show invoices for these clients and filer <> Acount 3.

The new tabel must contain only  columns "Company code, Client name, Invoice ID, Balance and local account

Thank you.

 

 

mihaistanca7_0-1705095464074.png

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_0-1705123636726.png

 

 

Expected result table = 
VAR _t =
    ADDCOLUMNS (
        SUMMARIZE ( Balance, Balance[Company code], Balance[Client name] ),
        "@balance total", CALCULATE ( SUM ( Balance[Balance] ) )
    )
VAR _topfive =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        _t,
        ORDERBY ( [@balance total], DESC ),
        PARTITIONBY ( Balance[Company code] )
    )
VAR _topfivelist =
    SUMMARIZE ( _topfive, Balance[Company code], Balance[Client name] )
VAR _expectedresult =
    CALCULATETABLE (
        FILTER ( Balance, Balance[Local account] <> "Account 3" ),
        TREATAS ( _topfivelist, Balance[Company code], Balance[Client name] )
    )
RETURN
    SUMMARIZE (
        _expectedresult,
        Balance[Company code],
        Balance[Client name],
        Balance[Invoice ID],
        Balance[Balance],
        Balance[Local account]
    )

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

HI,

Please try using Onedrive, Dropbox, or googledrive, and then share the link of the file.

Thanks.


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_0-1705123636726.png

 

 

Expected result table = 
VAR _t =
    ADDCOLUMNS (
        SUMMARIZE ( Balance, Balance[Company code], Balance[Client name] ),
        "@balance total", CALCULATE ( SUM ( Balance[Balance] ) )
    )
VAR _topfive =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        _t,
        ORDERBY ( [@balance total], DESC ),
        PARTITIONBY ( Balance[Company code] )
    )
VAR _topfivelist =
    SUMMARIZE ( _topfive, Balance[Company code], Balance[Client name] )
VAR _expectedresult =
    CALCULATETABLE (
        FILTER ( Balance, Balance[Local account] <> "Account 3" ),
        TREATAS ( _topfivelist, Balance[Company code], Balance[Client name] )
    )
RETURN
    SUMMARIZE (
        _expectedresult,
        Balance[Company code],
        Balance[Client name],
        Balance[Invoice ID],
        Balance[Balance],
        Balance[Local account]
    )

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi and thank you for answer

There is an error at line 15 and i don't understand why

mihaistanca7_0-1705141321274.png

 

Hi, please share your sample pbix file.

Thanks.


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi

Because i am a new user i cannot attach any file, pbix or XLSX.Can i use email or other method?

Thank you

HI,

Please try using Onedrive, Dropbox, or googledrive, and then share the link of the file.

Thanks.


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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.