Forum Discussion

Patv's avatar
Patv
Icon for Helper II rankHelper II
4 years ago

create calculated column to get Max date from different columns from same table

HI Friends, 

I have an easy task to solve but can't able to do it.  I have a table with ID, col1, col2, col3 and I want to create a calucated column  ( not measure)  that gets max date of col1, col2, col3. I can achive the expected result by creating measure using below formula but as I said I want to create a column. I used Max funciton but it doesn't work. Could you please help me figure it out? Thank you in advance!

 

MaxDate =
MAXX(
{
MAX(table[Col1]),
MAX(table[Col2]),
MAX(table[Col3])
},
[Value]
)

 

 

3 Replies

  • Hi Patv 

     

    Try this code to find the MAX date and create a calculated column:

    Max Date = max(MAX('Table'[Col1],'Table'[Col2]),'Table'[Col3])

     

    Output:

     

     

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

    • Patv's avatar
      Patv
      Icon for Helper II rankHelper II

      Hi VahidDM,

      Thank you for replying. This solution works if I have a Storage Mode = "Import". Currenlty, I have a Storage Mode = DirectQuery and when I apply below formula, I get an error ORA-00932: inconsistent Datatypes: expected DATE got NUMBER. The exception was raised by the IDbCommand Intercace. ( attached sceen below).  In  my table, All the date columns have datatype = Date and ID has datatype = Number.  Would you please help me how to solve it?

      Max Date = max(MAX('Table'[Col1],'Table'[Col2]),'Table'[Col3])

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Patv,

    AFAIK, power bi has limited the calculated column Dax functions usage when you are working with 'direct query' mode. So I think you need to use measure expression instead.

    Regards,

    Xiaoxin Sheng