Forum Discussion
Issue with Calculated Column Referencing Another Table Created using REST APIs
- Anonymous1 year ago
Hi Anonymous,
Thanks for posting your question in the Microsoft Fabric Forum Community.
To make your DAX expression work, the best way is to create a proper relationship between your calculated table (TestCalculatedTable) and the Inventory table before adding the new column. Without this relationship, Power BI can't understand how to pull data from the Inventory table into the calculated column, which causes the error.
Thanks & regards,
Prasanna Kumar - 1 year ago
Hi Anonymous It is because calculated columns in Power BI require a relationship or proper context to reference another table. Without a relationship, functions like RELATED cannot resolve the dependency, leading to errors. Ensure a relationship exists between TestCalculatedTable and Inventory before creating the calculated column. Update your code to check and create relationships programmatically if missing, and refresh the model to apply the changes, ensuring the calculated column operates correctly in all environments.
- 1 year ago
Hi Anonymous
You're facing a nuanced issue when programmatically adding a calculated column to a calculated table (TestCalculatedTable) in Power BI using the Tabular Object Model (TOM). Specifically, the DAX expression for the new column (StockStatus) references another table (Inventory), which leads to errors in the Power BI Service unless a relationship exists between the two tables. Your observations correctly identify the root cause: calculated columns cannot reference columns from unrelated tables unless there's a defined relationship in the model. Using RELATED() without a relationship also fails, as RELATED() relies on an existing relationship to fetch values from the related table. While this works fine when you query the model using Execute(Test Query)—because it executes in a flexible evaluation context—Power BI Service enforces stricter semantic rules during dataset refresh and report rendering. The solution that worked was to explicitly create a relationship between TestCalculatedTable and Inventory before adding the calculated column, which then allowed RELATED() to work correctly and populate values as expected. Your AddCalculatedColumn() method appears well-structured and follows best practices by validating the column's existence, adding it if not present, and calling RequestRefresh(Tabular.RefreshType.Calculate). However, the key insight is that Power BI requires a relationship between tables for cross-table column references in calculated columns, especially in production scenarios like Service or Embedded reports. Without that relationship, even valid-looking DAX fails because of the evaluation context limitations.
Hi Anonymous,
Thanks for posting your question in the Microsoft Fabric Forum Community.
To make your DAX expression work, the best way is to create a proper relationship between your calculated table (TestCalculatedTable) and the Inventory table before adding the new column. Without this relationship, Power BI can't understand how to pull data from the Inventory table into the calculated column, which causes the error.
Thanks & regards,
Prasanna Kumar