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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Smitesh
Regular Visitor

Creating a Dax query to get sum of a column from Table A if the record matches in Table B

I have 2 tables

1. Gold_Staff_Campaign

2. FX_Data

 

i want to create a DAX formula to calculate the Total Profit residing in Table FX_Data under column "Profit" if the Account Number in Gold_Staff_Campaign matches with Account Number in FX_Data. 

 

I have tried below formula but its not working

 

1. 

ProfitColumn =
VAR CurrentFORACID =
    SELECTCOLUMNS (
        Gold_Diwali_Campaign,
        "FORACID", Gold_Diwali_Campaign[FORACID]
    )
RETURN
    CALCULATE (
        SUM ( FX_Data_2022_Onwards[Profit w.r.t real time rate(AED)] ),
        FILTER (
            FX_Data_2022_Onwards,
            FX_Data_2022_Onwards[FORACID] = CurrentFORACID
        ),ALL ( Gold_Diwali_Campaign )
    )
4 REPLIES 4
johnbasha33
Super User
Super User

@Smitesh 
ProfitColumn =
CALCULATE (
SUM ( FX_Data_2022_Onwards[Profit w.r.t real time rate(AED)] ),
RELATED ( Gold_Staff_Campaign[FORACID] )
)

Smitesh_1-1712310063777.png

@johnbasha33 I have tried this earlier and it shows me an error that Field doesnt exist or does not have a relationship. However relationship has been created on FORACID

Anonymous
Not applicable

Hi @Smitesh 

 

Are there any relationship between these two tables?

You can create a one-to-many relationship and use the related() or userelationship() function to get your target.

If you can provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Smitesh_2-1712310203618.png

@Anonymous Yes relationship exist between the two tables.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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