Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How to create a calculated column with same value in every row with a calculated value

Hi,   I am trying to create a calculated column using DAX Calculate function. I want all my rows to have the same value that was calculated using CALCULATE function. I want all rows of thisFi...
  • MattB-Motive's avatar
    2 years ago

    Hi Anonymous 

     

    DAX works a little differently in Calculated Columns because of Row Context. When using DAX in a measure, you have to be more aware of it's Filter Context. Row Context allows you to reference a 'naked' column in a row without an aggregating funtion, because DAX knows that row and column you mean.

     

    When used in a Calculated Column the Calculate function has an interesting behaviour, it 'converts' the value of each row into a Filter Context for the calculation. In your case, for the first row this creates a filter context of rDate = -2, dayOfWeek = 0, ...etc. So to get the same value for every row, you need to first clear the relevant filter context in the Calculate function.

     

    Something like:  

    thisFiscalWeek = CALCULATE(MAX('Date Hierarchy'[fiscalWeek]), ALL('Date Hierarchy'), 'Date Hierarchy'[rDate] = 0)

     

    Generally (depending on your use of the column) it is usually better to use a Measure instead of the Calculated Column.

     

    These references might be useful:

    Context in DAX Formulas - Microsoft Support

    Row context in DAX - SQLBI