Forum Discussion

navind's avatar
navind
Regular Visitor
2 years ago
Solved

Calculation group with multiple facts

Hi Guys, 

We have below calculation group  code for single  fact which works fine, we are calling other measure which we create tocalaulate amount  along with cal item

Calculation item = CALCULATE(SELECTEDMEASURE(),FILTER('FACT_SUMMARY','FACT_SUMMARY'[ProductID] = "Grade1"))
 
Provide accurate results, we need to expand the code to other facts which has similar Product ID , As we tried below code if skews numbers
 Calculation item
 
VAR _IsProductID=
    CONTAINS('FACT_SUMMARY', 'FACT_SUMMARY'[ProductID], "Grade1")
    ||
 CONTAINS('FACT_SUMMARY', 'FACT_SUMMARY2'[ProductID], "Grade1")
    ||
  CONTAINS('FACT_SUMMARY', 'FACT_SUMMARY3'[ProductID], "Grade1")
RETURN
IF(
    _IsProductID,
    CALCULATE(
        SELECTEDMEASURE()
    )
)
 
Final Ouput  in matrix :
                              Amt from Fact 1         Amt from Fact 2                   Amt from Fact 2
      Grade 1                             20                                       5                                    5
 
Regards,
9
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi navind ,

    It seems like you're trying to apply a calculation item across different fact tables, but you're encountering issues with skewed numbers.

     

    Firstly, it's important to ensure that your calculation item logic correctly identifies the relevant Product IDs across all fact tables. The approach you've taken with the CONTAINS function should work in theory, but it's crucial to ensure that the relationships between your fact tables and the dimension table containing the Product IDs are correctly set up in your model. This ensures that the CONTAINS function can accurately filter the rows.

     

    However, using CONTAINS in this manner might not be the most efficient way to filter for "Grade1" across multiple fact tables. Instead, consider leveraging the existing relationships in your model. If your fact tables are related to a common dimension table (e.g., a Product dimension table), you can simplify your calculation item by filtering on this dimension table directly, assuming that the ProductID "Grade1" is present in this dimension.

     

    Here's a revised approach:

     

    Calculation item =
    CALCULATE(
        SELECTEDMEASURE(),
        FILTER(
            ALL('ProductDimension'), 
            'ProductDimension'[ProductID] = "Grade1"
        )
    )

     

    In this revised approach, replace 'ProductDimension' with the actual name of your Product dimension table that is related to your fact tables. This method assumes that there's a single, consistent Product dimension that all your fact tables relate to, which simplifies the filtering logic.

     

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi navind ,

    It seems like you're trying to apply a calculation item across different fact tables, but you're encountering issues with skewed numbers.

     

    Firstly, it's important to ensure that your calculation item logic correctly identifies the relevant Product IDs across all fact tables. The approach you've taken with the CONTAINS function should work in theory, but it's crucial to ensure that the relationships between your fact tables and the dimension table containing the Product IDs are correctly set up in your model. This ensures that the CONTAINS function can accurately filter the rows.

     

    However, using CONTAINS in this manner might not be the most efficient way to filter for "Grade1" across multiple fact tables. Instead, consider leveraging the existing relationships in your model. If your fact tables are related to a common dimension table (e.g., a Product dimension table), you can simplify your calculation item by filtering on this dimension table directly, assuming that the ProductID "Grade1" is present in this dimension.

     

    Here's a revised approach:

     

    Calculation item =
    CALCULATE(
        SELECTEDMEASURE(),
        FILTER(
            ALL('ProductDimension'), 
            'ProductDimension'[ProductID] = "Grade1"
        )
    )

     

    In this revised approach, replace 'ProductDimension' with the actual name of your Product dimension table that is related to your fact tables. This method assumes that there's a single, consistent Product dimension that all your fact tables relate to, which simplifies the filtering logic.

     

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.