cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Transform text (YYYYMMDD) to Date when some cells are empty

Hi,

 

In the Power Query Editior I have a column, lets call it "column" with a date in Text-format

  • When Date is filled it will show: YYYYMMDD
  • When Date is not filled it will show: 0

 

I would like to add a column and transform the Text to a Date (DD-MM-YYYY), but to leave emtpy when "0"

I would use this formular when all cells are filled, but it will not work with the cells containing "0":

 

Date =

Date.FromText(
Text.Range([column], 0, 4) &
"-" &
Text.Range([column], 4, 2) &
"-" &
Text.Range([column], 6, 2) )

 

How would I handle this in DAX?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Transform text (YYYYMMDD) to Date when some cells are empty

@Blaest 

Add an if condition to check. 

=if [Column] = "0" 
then 0 
else
Date.FromText(
Text.Range([Column], 0, 4) &
"-" &
Text.Range([Column], 4, 2) &
"-" &
Text.Range([Column], 6, 2) )

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

View solution in original post

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: Transform text (YYYYMMDD) to Date when some cells are empty

@Blaest 

Add an if condition to check. 

=if [Column] = "0" 
then 0 
else
Date.FromText(
Text.Range([Column], 0, 4) &
"-" &
Text.Range([Column], 4, 2) &
"-" &
Text.Range([Column], 6, 2) )

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

View solution in original post

Highlighted
Regular Visitor

Re: Transform text (YYYYMMDD) to Date when some cells are empty

Thanks,

 

I wanted to lease cells emtpy when "0", so I tweaked it a bit:

 

 

if [column] = "0" then ""
else
Date.FromText( Text.Range([column], 0, 4) &
"-" &
Text.Range([column], 4, 2) &
"-" &
Text.Range([column], 6, 2) )

 

 

Helpful resources

Announcements
Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors