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
Smitesh
New Member

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
Continued Contributor
Continued Contributor

@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

v-zhengdxu-msft
Community Support
Community Support

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

@v-zhengdxu-msft Yes relationship exist between the two tables.

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.

Top Solution Authors