Forum Discussion

AdilDawood's avatar
AdilDawood
New Member
5 years ago
Solved

Sumif / DAX

I am relatively new in power BI and not sure how to get the following results in power bi. Can someone help

 

 

 

 

  • AdilDawood 

    Go to Modeling Tab, click on New Table create a new table with the following code. This will list all the accounts from Both FROM and TO columns.

    All Acounts = 
    SELECTCOLUMNS(
        DISTINCT(
            UNION( VALUES(Accounts[From Account]), VALUES(Accounts[To Account]))
        ),
        "Account", Accounts[From Account]
    )

     

    Insert a Table B Visual and bring the Account field from the new table. Add the following measure.

     

    Balance of Accounts = 
    
    var _Acc = SELECTEDVALUE('All Acounts'[Account]) return
     
    CALCULATE( SUM(Accounts[Amount]) , Accounts[To Account] = _Acc ) - 
    CALCULATE( SUM(Accounts[Amount]) , Accounts[From Account] = _Acc )

     

    Result

    ________________________

    If my answer was helpful, please click Accept it as the solution to help other members find it useful

    Click on the Thumbs-Up icon if you like this reply πŸ™‚


    Website YouTube  LinkedIn

     

     

4 Replies

  • AdilDawood 

    Go to Modeling Tab, click on New Table create a new table with the following code. This will list all the accounts from Both FROM and TO columns.

    All Acounts = 
    SELECTCOLUMNS(
        DISTINCT(
            UNION( VALUES(Accounts[From Account]), VALUES(Accounts[To Account]))
        ),
        "Account", Accounts[From Account]
    )

     

    Insert a Table B Visual and bring the Account field from the new table. Add the following measure.

     

    Balance of Accounts = 
    
    var _Acc = SELECTEDVALUE('All Acounts'[Account]) return
     
    CALCULATE( SUM(Accounts[Amount]) , Accounts[To Account] = _Acc ) - 
    CALCULATE( SUM(Accounts[Amount]) , Accounts[From Account] = _Acc )

     

    Result

    ________________________

    If my answer was helpful, please click Accept it as the solution to help other members find it useful

    Click on the Thumbs-Up icon if you like this reply πŸ™‚


    Website YouTube  LinkedIn

     

     

    • AdilDawood's avatar
      AdilDawood
      New Member

      Thanks Ashish 

      Although your solution does work for this data but this is a sample data and actual data is quite large. The solution provided by Fowmy works better on that. 

      Thanks anyway for the resposne.