Forum Discussion

Lachu1935's avatar
Lachu1935
Regular Visitor
7 months ago
Solved

One Lake

Hi Team,
 
While uploading the data file to One Lake, I noticed that the data types for some columns were automatically recognized incorrectly. For example, my date column was mistakenly identified as text format. Unfortunately, I couldn't find an option to change the data type. The issue persisted last night, and I was unable to run it through the SQL endpoint.
Could anyone please guide me on how to change the data type?
Thank you.
  • Hi Lachu1935,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you Cookistadorchris_andrews and deborshi_nag for the prompt response. 

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.

     

    Thanks and regards,

    Anjan Kumar Chippa

6 Replies

  • Hi Lachu1935 ,

     

    The issue here is that Fabric will not reliably auto-detect ambiguous date types (non ISO dates). As you are importing as a csv it will struggle to identify your dates as dates, read them as a string and format as text.

     

    The solution here is to do one of the following:

    1. Structure your dates in your source data to a common ISO format like 2026-01-30 (yyyy‑mm‑dd)
    2. Change the column format using a notebook as Cookistador suggests (but this seems to be not working)
    3. Bring your data in using Dataflow Gen2 and using the Power Query editor to change the column format

    I would personally get into the habit of using ISO date formats in data reporting if possible. You will have far less trouble when ingesting and transforming data. 

     

    EDIT:

    Have you tried Data Wrangler in notebooks? This assists you in transforming data within notebooks.

     

    df = spark.read.option("header", "true").csv("Files/myfolder/myfile.csv")

    display(df)

    Accelerate Data Prep with Data Wrangler - Microsoft Fabric | Microsoft Learn

     

  • Hello Lachu1935 

     

    It is best to drop the CSV file in /Files (consider it a Landing zone), read the content using PySpark explicitly specifying the schema, and finally write to /Tables area in your "bronze" schema. I attach a code snippet. 

     

    from pyspark.sql.types import StructType, StructField, StringType, IntegerType, DoubleType, DateType
    
    schema = StructType([
        StructField("order_id",     StringType(), True),
        StructField("customer_id",  StringType(), True),
        StructField("order_date",   DateType(),   True),   # <-- DateType; parsed using dateFormat
        StructField("channel",      StringType(), True),
        StructField("quantity",     IntegerType(),True),
        StructField("unit_price",   DoubleType(), True)
    ])
    
    src_path = "/lakehouse/default/Files/ingest/orders/"
    
    df = (
        spark.read
             .format("csv")
             .option("header", "true")          # CSV has headers
             .option("mode", "PERMISSIVE")      # don't fail job on a few bad lines
             .option("dateFormat", "dd-MM-yyyy")# <-- critical: tell Spark how to parse DateType
             .schema(schema)
             .load(src_path)
    )
    
    spark.sql("CREATE DATABASE IF NOT EXISTS bronze")
    
    (df.write
       .format("delta")
       .mode("append")              # or "overwrite" for full refresh
       # .partitionBy("order_date") # uncomment if partitioning is helpful for your volume
       .saveAsTable("bronze.orders")
    )

     

     

  • Hi Lachu1935 

    it is probably related to the format of your date

    It is waiting date in us format so this is why it is recognized as text (in which area is deployed your fabric capacity?)

     

    Instead of doing a auto load from file to table, you can create a small notebook to convert the column in the right format:

    df = spark.read.format("csv").option("header", "true").load("Files/yourfile.csv")

    df = df.withColumn("CREATED_DATE", F.to_date("CREATED_DATE", "dd-MM-yyyy"))

    df.write.format("delta").mode("overwrite").saveAsTable("mra_dec_2025")

  • Lachu1935's avatar
    Lachu1935
    Regular Visitor

    Thank you Team for such a meaningful guidance from you all , the issue was now resloved thanlks for the support Thank you

  • Lachu1935's avatar
    Lachu1935
    Regular Visitor

    I have tried this, but the column still changes to all null values. Could this be an issue with the CSV file? I have checked, and the column shows as a data format.

  • v-achippa's avatar
    v-achippa
    Community Support

    Hi Lachu1935,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you Cookistadorchris_andrews and deborshi_nag for the prompt response. 

     

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.

     

    Thanks and regards,

    Anjan Kumar Chippa