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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors