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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

How to do a sum on a disconnected table

I have two tables: 

  • Table A has accountID
  • Table B has accountID, increment, value
  • The two tables are disconnected.

How do I write a calculated column in table A, that will sum up the value in table B but only for rows where the accountIDs match  and increment = 1?

 

I've made various attempts and my best one is returning a value where I know for sure there should not be a match and it should be returning a blank.

 

=CALCULATE(Sum(tableB[Value]),All(tableB[accountID])=tableA[accountID],tableB[Increment]=1)

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

 Ok I think I've solved it:

=CALCULATE(Sum(tableB[Value]),Filter(ALL(tableB),tableB[AccountID]=tableA[AccountID]&&[Increment]=1))

View solution in original post

jdbuchanan71
Super User
Super User

Hello @Anonymous 

You can use TREATAS to create the vitual relationship.

Column = 
CALCULATE (
    SUM ( TableB[Value] ),
    TREATAS ( VALUES ( TableA[AccountID] ), TableB[AccountID] ),
    TableB[Increment] = 1
)

2020-06-20_6-49-28.png 

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

Hello @Anonymous 

You can use TREATAS to create the vitual relationship.

Column = 
CALCULATE (
    SUM ( TableB[Value] ),
    TREATAS ( VALUES ( TableA[AccountID] ), TableB[AccountID] ),
    TableB[Increment] = 1
)

2020-06-20_6-49-28.png 

Anonymous
Not applicable

 Ok I think I've solved it:

=CALCULATE(Sum(tableB[Value]),Filter(ALL(tableB),tableB[AccountID]=tableA[AccountID]&&[Increment]=1))

HI @Anonymous,

You can try to use allselected function to extract value from other table(even if they do not exist relationship) and stored in a variable, then you can compare with current table fields and variable to filter correspond records. (it should works on both measure and calculate column expressions)

formula =
VAR idList =
    ALLSELECTED ( tableA[AccountID] )
RETURN
    CALCULATE (
        SUM ( tableB[Value] ),
        FILTER ( ALLSELECTED ( tableB ), tableB[AccountID] IN idList && [Increment] = 1 )
    )

Managing “all” functions in DAX: ALL, ALLSELECTED, ALLNOBLANKROW, ALLEXCEPT 

The IN operator in DAX 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.