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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Finding the sum from two columns on the same table

Hello, I am new to power bi but I am having hard time finding the sum of two columns on the same table. Example: I want to find the total shipments going to each state. Thank You for your help.

Table1

IdFromToShipments
1New YorkTexas52
2CA New York15
3TexasCA32
4WIMN58
5MNTexas40
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Try formula as below:
calculated table:

Table = 
DISTINCT (
    UNION (
        SELECTCOLUMNS ( Table1, "State", Table1[From] ),
        SELECTCOLUMNS ( Table1, "State", Table1[To] )
    )
)

calculated column:

Total Shipments = 
CALCULATE (
    SUM ( Table1[Shipments] ),
    FILTER ( 'Table1', 'Table1'[From] = 'Table'[State] )
)
    + CALCULATE (
        SUM ( Table1[Shipments] ),
        FILTER ( 'Table1', 'Table1'[To] = 'Table'[State] )
    )

The result will show as below:

4.png

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Try formula as below:
calculated table:

Table = 
DISTINCT (
    UNION (
        SELECTCOLUMNS ( Table1, "State", Table1[From] ),
        SELECTCOLUMNS ( Table1, "State", Table1[To] )
    )
)

calculated column:

Total Shipments = 
CALCULATE (
    SUM ( Table1[Shipments] ),
    FILTER ( 'Table1', 'Table1'[From] = 'Table'[State] )
)
    + CALCULATE (
        SUM ( Table1[Shipments] ),
        FILTER ( 'Table1', 'Table1'[To] = 'Table'[State] )
    )

The result will show as below:

4.png

Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank You So much!!!

ryan_mayu
Super User
Super User

@Anonymous 

in PQ, select both ID and shipments columns and unpivot other columns

1.png

then you can get what you want

3.PNG

2.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@Anonymous 

what's the expected result based on your sample data?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

it would be total shipment would be = sum of shipment( From + To)

StateShipment
New York 67
CA47
Texas124
MN98
WI58
Anonymous
Not applicable

thanks for the reply, when I try to create the Location table using that formula(location = distinct(distinct(Table[from]),distinct(Table[to]))), i am getting error

amitchandak
Super User
Super User

@Anonymous , to what brings from and to in same column and show the sum ?

 

if yes you need to create a table 

location = distinct(distinct(Table[from]),distinct(Table[to]))

 

join with both to and from, one will be inactive assume to 

 

then create a measure 

measure = sum(Table[Shipments])  + CALCULATE(sum(Table[Shipments]), userelationship(table[to], location [from]))

 

if needed refer

https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in-power-bi

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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