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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
manojsv
Regular Visitor

DAX to calculate sum based on another table

Hello All,

 

I have created a one to many relationship between Dim_ProductCost which has the source as excel  and Fact_ProductsList table uses direct query from SQLServer.  I wanted to calculate the sum of cost of all products in the fact table by looking up the corresponding cost value from the dim table using productcostid field.   The count i am expecting to get is 199.25 as shown in the table and have used the following measure to get the count

 

_m_sum_costsaving = CALCULATE(SUMX('Fact_ProductsList', RELATED(Dim_ProductCost(ProductCostValue))
 

I am getting the following error when using the excel(Dim_ProductCost) stored locally and other table (Fact_ProductsList) uses direct query. but, not getting any error if i imported the fact table. Can you help us in getting resolved this issue when using both the direct query and lookup data from the local file.   I would appreciate any suggestions to acheive the desired result.

 

"The column 'Dim_ProductCost(ProductCostValue' either doesn't exist or doesn't have a relationship to any table available in the current context."

 

  Excel Data(Dim_ProductCost) has the cost info like this

ProductCostIDProductCostValue
112
224
328.65
418.9
550.6
618.1

 

Table 2(Fact_ProductsList table) has the product related info.

 

ProductIDProductNameProductCostIDLookupValues from ProductCost table
12A112
14B550.6
19C328.65
20D112
21E224
12A112
32F224
15G112
32H224
   199.25

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @manojsv ,

For your issue, it is caused by the Mixed mode in which Related doesn’t work well. You can create a measure like so:

Measure =
VAR t =
    FILTER (
        CROSSJOIN (
            Fact_ProductsList,
            SELECTCOLUMNS (
                Dim_ProductCost,
                "Product_Cost_Value", Dim_ProductCost[ProductCostValue],
                "Product_Cost_ID", Dim_ProductCost[ProductCostID]
            )
        ),
        [Product_Cost_ID] = Fact_ProductsList[ProductCostID]
    )
RETURN
    SUMX ( t, [Product_Cost_Value] )

sum.PNG

 

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @manojsv ,

 

Is this problem sloved?
 
If it is sloved, could you kindly accept it as a solution to close this case?  
 
If not, please let me know.  
 
Best Regards
Icey
Icey
Community Support
Community Support

Hi @manojsv ,

For your issue, it is caused by the Mixed mode in which Related doesn’t work well. You can create a measure like so:

Measure =
VAR t =
    FILTER (
        CROSSJOIN (
            Fact_ProductsList,
            SELECTCOLUMNS (
                Dim_ProductCost,
                "Product_Cost_Value", Dim_ProductCost[ProductCostValue],
                "Product_Cost_ID", Dim_ProductCost[ProductCostID]
            )
        ),
        [Product_Cost_ID] = Fact_ProductsList[ProductCostID]
    )
RETURN
    SUMX ( t, [Product_Cost_Value] )

sum.PNG

 

Best Regards,

Icey

 

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

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.