Forum Discussion
Function RELATED expects a fully qualified column reference as its argument
- 7 years ago
Hi again cwozniak03
- v-frfei-msft 's reply is correct - RELATED cannot traverse a many-to-many relationship.
- I take it you creating a calculated column in the 'All Grant Amount's table, rather than a measure? It would appear so based on the use of EARLIER. It might be considered better practice to create a measure, depending how the result of this calculation will be used, but I won't dwell on that point here.
- Regardless of whether you create a calculated column or measure, I believe your formula can be written more simply by applying filters to individual columns rather than using the FILTER function over the 'All Grant Amounts' table, and there is no need to use the RELATED function to do this. If this is a calculated column, I would probably write an expression structured like this using variables to store values from the current row and then applying individual column filters within CALCULATE:
College_Totals_No_Loans = VAR CurrentStudentNumber = 'All Grant Amounts'[student_number] VAR CurrentCollegeID = 'All Grant Amounts'[college_id] RETURN CALCULATE ( SUM ( 'All Grant Amounts'[grant_amount] ), 'All Grant Amounts'[student_number] = CurrentStudentNumber, 'All Grant Amounts'[college_id] IN { CurrentCollegeID, 0 }, 'funding_types'[funding_type_id] <> 3,
// Clear all filters on the table,
// since CALCULATE adds all values from current row to filter context
// Filters specified above will still apply
ALL ( 'All Grand Amounts' ) )
The above expression might not quite do what you want (I made a few guesses about the logic), but I think this is the sort of structure you should use.
Could you describe roughly in words what the calculation should be returning, perhaps with some sample data?
Regards,
Owen
Hi again cwozniak03
- v-frfei-msft 's reply is correct - RELATED cannot traverse a many-to-many relationship.
- I take it you creating a calculated column in the 'All Grant Amount's table, rather than a measure? It would appear so based on the use of EARLIER. It might be considered better practice to create a measure, depending how the result of this calculation will be used, but I won't dwell on that point here.
- Regardless of whether you create a calculated column or measure, I believe your formula can be written more simply by applying filters to individual columns rather than using the FILTER function over the 'All Grant Amounts' table, and there is no need to use the RELATED function to do this. If this is a calculated column, I would probably write an expression structured like this using variables to store values from the current row and then applying individual column filters within CALCULATE:
College_Totals_No_Loans = VAR CurrentStudentNumber = 'All Grant Amounts'[student_number] VAR CurrentCollegeID = 'All Grant Amounts'[college_id] RETURN CALCULATE ( SUM ( 'All Grant Amounts'[grant_amount] ), 'All Grant Amounts'[student_number] = CurrentStudentNumber, 'All Grant Amounts'[college_id] IN { CurrentCollegeID, 0 }, 'funding_types'[funding_type_id] <> 3,
// Clear all filters on the table,
// since CALCULATE adds all values from current row to filter context
// Filters specified above will still apply
ALL ( 'All Grand Amounts' ) )
The above expression might not quite do what you want (I made a few guesses about the logic), but I think this is the sort of structure you should use.
Could you describe roughly in words what the calculation should be returning, perhaps with some sample data?
Regards,
Owen
Owen,
Thank you so much for this, I am just starting out with PowerBI and this is great to know that you can do things like this.
Also good to know that RELATED doesnt work with M2M.
Chris