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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gvg
Post Prodigy
Post Prodigy

Summarize data in one column by values in the other two

Hi,

This is from accounting. I have a table with Debit and Credit account numbers in different columns and value field in the third column. How do I summarize data to arrive at account balance, please? Account balance is calculated as sum of Credit amounts minus sum of Debit amounts.

 

My source table looks like this:

 

    DebitAccount    CreditAccount    Amnt

    123                  456                     100

    322                  456                       50

    456                  789                       70

    456                  322                      200

 

And the resulting table should look like this:

 

    Account   Amnt

    123         -100

    322          150

    456         -120

    789            70

   

Could you please help? I was trying to build a measure with SUMMARIZE, but with no luck.  I know how to build a reference table and make a suitable table for simple summarizing. But my database is huge and I thought that probably making a calculated measure will be more practical.

1 ACCEPTED SOLUTION

Then your best bet may be to do data folding at query stage when you are adding data source (using SQL statements). Assuming you have access to query database.

View solution in original post

6 REPLIES 6
Chihiro
Solution Sage
Solution Sage

You can unpivot Source table's [DebitAccount] & [CreditAccount]. Then adjust data type as needed.

 

Rest can be done in DAX.

In Modeling ribbon tool, add "New Table".

TableName = DISTINCT(Source[Account])

 

Add column:

 

Amnt =
SUMX (
    FILTER (
        Source,
        Source[Account] = Result[Account]
            && Source[Attribute] = "CreditAccount"
    ),
    [Amnt]
)
    - SUMX (
        FILTER (
            Source,
            Source[Account] = Result[Account]
                && Source[Attribute] = "DebitAccount"
        ),
        [Amnt]
    )

Thanks @Chihiro , but my original table is huge, several gigabytes. No way to build a calculated measure?

Then your best bet may be to do data folding at query stage when you are adding data source (using SQL statements). Assuming you have access to query database.

That's an idea! Thanks.

MarcelBeug
Community Champion
Community Champion

A solution in Power Query would be:

 

let
    Source = Accounting,
    Restructured = Table.FromColumns({Source[DebitAccount]&Source[CreditAccount],List.Transform(Source[Amnt], each _ * -1)&Source[Amnt]},{"Account", "Amnt"}),
    Grouped = Table.Group(Restructured, {"Account"}, {{"Amnt", each List.Sum([Amnt]), type number}})
in
    Grouped
Specializing in Power Query Formula Language (M)

Does this create a new table? It wouldn't work for me as my original table is very big.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.