Forum Discussion
How to create custom column based on value in cell?
- 3 years ago
pls try this
Column = VAR t1 = [ID] RETURN MAXX( FILTER(ALL('Table'),'Table'[ID]=t1&&'Table'[Question]="Contractor?"),[Answer])
pls try this
Column =
VAR t1 = [ID]
RETURN MAXX(
FILTER(ALL('Table'),'Table'[ID]=t1&&'Table'[Question]="Contractor?"),[Answer])This totally helped! Thank you so much. Could you explain the code so that i can learn what is does?
- Ahmedx3 years agoSuper User
Your DAX code is used to create a calculated column in Power BI or Power Pivot, based on specified conditions and operations. Let's break it down step by step:
1) VAR t1 = [ID]: In this line, a temporary variable t1 is created, which holds the value of the current row's [ID] column. This is done to avoid repeated access to [ID] in subsequent operations.
2) FILTER(ALL('Table'), 'Table'[ID] = t1 && 'Table'[Question] = "Contractor?"): Here, the FILTER function is used to filter the 'Table' based on certain conditions. ALL('Table') is used to ignore any existing filters on the table and work with it entirely. The filtering conditions involve comparing the [ID] column with the temporary variable t1 and the [Question] column with the text "Contractor?".
3) MAXX(..., [Answer]): The MAXX function is applied to the filtered result and calculates the maximum value of the [Answer] column within the filtered table.
As a result, for each row in the [ID] column, the maximum value of the [Answer] column satisfying the filtering conditions based on [ID] and [Question] will be computed.
The code appears logical and performs the described actions. However, it's worth considering performance implications, as using FILTER(ALL(...)) can potentially impact performance, especially with large datasets.