Forum Discussion

memocyp's avatar
memocyp
Frequent Visitor
9 years ago
Solved

Calculated Column based on a condition

Hi,   I have the following table where values are coming from different tables. It's a star schema where I have Sales Facts, Promo Dimension, Product Dimension. What i need is a column FLAG ...
  • jmalone's avatar
    jmalone
    9 years ago

    There may be some confusion between your description of the schema/model and the attached screenshot. The picture makes it appear like your three columns are in a single table. However, after reading your description, you should be able to create a calculated column using the IF() and RELATED() functions.

     

    To help understand RELATED(), you can simply add a calculated column in the Promo Dimension table:

    Related Test Column = RELATED('Product Dimension'[Product_HIER4_NAME])

     

    If your model is set up correctly (with a one-to-many relationship from Product Dimension to Promo Dimension), you should see the Product_HIER4_Name values in this new column. If it doesn't work, you might need to check the relationship between these two tables.

     

    Once you've gotten the RELATED() function to work, you can use it in an IF() conditional statement. Also in Promo Dimension table.

    Something like:

    New Calculated Column = IF( RELATED('Product Dimension'[Product_HIER4_NAME]) = "Food" ) , TRUE() , FALSE() )

     

     

    This should return True for Food, and False for everything else.

    Just add the OR() function as mentioned earlier to use additional conditions.