Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Broeselchen
Helper III
Helper III

Number to date

Ok, I'll try it this https://community.powerbi.com/t5/Desktop/Zahl-in-Datum-%C3%A4ndern-Zellen-mit-0-Werten/m-p/3008604#M... in english:

 

I want to change a number into a date. It only works, if there isn't a 0 in the column (KAHJMT). But, if there is a 0, it's a problem (KAGDAT).

Broeselchen_0-1673426317213.png

Broeselchen_1-1673426328034.png

 

1 ACCEPTED SOLUTION

@Broeselchen You can replace with day as 01 if its 00. Use below code for it.

Kagdat_datum = 
var _day = if(int(RIGHT ( [KAGDAT], 2 ))=0,01,RIGHT ( [KAGDAT], 2 ))
return IF (
    [KAGDAT] = 0 || [KAGDAT] = BLANK() ,
    BLANK (),
 DATE ( LEFT ( [KAGDAT], 4 ), MID ( [KAGDAT], 5, 2 ),_day)
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

14 REPLIES 14
Samarth_18
Community Champion
Community Champion

Hi @Broeselchen ,

 

Please replace blank with BLANK() in your code. It should be like below:-

Kagdat_datum =
IF (
    Customers[KAGDAT] = 0,
    BLANK (),
    DATE ( LEFT ( Customers[KAGDAT], 4 ), MID ( Customers[KAGDAT], 5, 2 ), RIGHT ( Customers[KAGDAT], 2 ) )
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

No, sorry:

Broeselchen_0-1673432124607.png

"An argument of the "DATE" function is of the wrong data type, or the result is too long or too short."

 

I tried it "KAGDAT" as number and as text.

@Broeselchen Please try this:-

Kagdat_datum =
IF (
    Customers[KAGDAT] = 0 || Customers[KAGDAT] = BLANK() ,
    BLANK (),
    DATE ( LEFT ( Customers[KAGDAT], 4 ), MID ( Customers[KAGDAT], 5, 2 ), RIGHT ( Customers[KAGDAT], 2 ) )
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

No, same problem : /

@Broeselchen Please confirm do you have anything in the column apart from 0 and 8 character value e.g.(YYYYMMDD)?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

No, there's nothing else.

@Broeselchen is it possible for you to share PBIX file after removing sensitive data?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Oh, now I made the list shorter and it works. So, you're right, there must be something in the dates. How can I finde the problem?

(I can't find a point to upload the csv...)

@Broeselchen you can upload it any drive and share it with open access or you can use website like https://wetransfer.com/ 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi @Broeselchen , We are getting this error due to you have some date which are 00.

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Ok! And do you have any solution for this problem?

@Broeselchen You can replace with day as 01 if its 00. Use below code for it.

Kagdat_datum = 
var _day = if(int(RIGHT ( [KAGDAT], 2 ))=0,01,RIGHT ( [KAGDAT], 2 ))
return IF (
    [KAGDAT] = 0 || [KAGDAT] = BLANK() ,
    BLANK (),
 DATE ( LEFT ( [KAGDAT], 4 ), MID ( [KAGDAT], 5, 2 ),_day)
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Yes!!!! Thank you so much!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.