Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 months ago
Solved

Adding calculated column to date table

Hi,   I've got a dimension date table with a dateid (yyyymmdd) and a currency table with fields: dateid, currency, value.  I want to add 4 columns to the date table, 1 for each currency with the v...
  • Ilgar_Zarbali's avatar
    9 months ago

    This won’t work while your Date table is local and the Currency table comes from a Power BI semantic model (DirectQuery for PBI datasets/AAS).
    In that setup, calculated columns (and calculated tables) can’t reference columns from a remote/semantic-model table. Only measures can cross that boundary at query time. The cryptic error you’re seeing is the symptom of that limitation.

    What you can do instead

    1)

    Bring Currency local (recommended if you truly need row-level columns)
    Import the currency data into the same model (from the original source or a dataflow).
    Once both tables are local, add 1 column per currency:

    USD :=
    VAR id = 'Date'[DateId]
    RETURN
    CALCULATE (
    MAX ( 'Currency'[Value] ),
    'Currency'[DateId] = id,
    'Currency'[Currency] = "USD"
    )

     

    Repeat for EUR/GBP/etc. (wrap with COALESCE(…, 0) if you need blanks as zeros).

     

    2)

    Do it in Power Query (materialize at refresh)
    If you can reach the currency source in Power Query, merge Date ↔ Currency on DateId and expand the needed columns (or pivot Currency to wide shape: one column per code). This gives you physical columns without DAX.

     

    3)

    Stay remote and use measures (no row columns)
    If moving the table isn’t possible, create measures instead of columns, e.g.:

     

    USD :=
    CALCULATE (
    MAX ( 'Currency'[Value] ),
    'Currency'[Currency] = "USD"
    )

     

    These will work across the relationship, but you won’t have row-level calculated columns for further calculated-column logic.

    Calculated columns can’t pull from a remote semantic model table. To get 4 currency columns on the Date table, either import the Currency table into the same model (or via PQ/dataflow) and then add the DAX columns, or materialize the join in Power Query. Measures are the only cross-model option if you must keep Currency remote.

     

    I hope it will help. If so, please give kudoes and accept it as a solution.

     

     

     

     

     

     

  • Kedar_Pande's avatar
    9 months ago

    You can't create calculated columns that reference tables from different semantic models. This is a hard limitation in Power BI.

    The only solution is to merge the currency values into your date table during data transformation using Power Query, before the data loads into the model.