Power BI convert eight digit yyyymmdd to date using DAX

MST QNB picture MST QNB · Jan 2, 2018 · Viewed 15.3k times · Source

I'm trying to convert eight digit yyyymmdd to date format with DAX function.

column = DATE(LEFT(TABLE[COLUMN],4),MID(TABLE[COLUMN],5,2),RIGHT(TABLE[COLUMN],2))

However, I've got an error because of the original column has some records with "00000000", so how can I make a default value with IF statement or are there any better solution?

Best regards

Answer

Bryant Avey picture Bryant Avey · Apr 24, 2018

What I typically do is just make 2 distinct Power Query steps and this is handled automatically.

  1. just make the yyyymmdd column a text column
  2. make the text column from step 1 a date column (when prompted, be sure to select 'Add New Step')
  3. replace errors with null

That's it. You can even Ctrl-Click to select multiple columns and combine them into the 1,2, and 3 steps with multiple columns.