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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Date field formatting

Hello people,

I'm creating indicators based on a sharepoint list, but the list returns two types of dates, (note below)

Screenshot_2.png

 
 

If I change my column to date, the numeral fields give an error.

 

Screenshot_3.png

 

Now if I change the field to Integers and then add a new step to date, the fields that had a date before return me an error, but the numeral fields return a date.

 

Screenshot_4.png

Can anyone help me find a solution?

2 ACCEPTED SOLUTIONS
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

It is an odd one, no idea why this is happening but you can fix it by adding an extra "transform" step as per below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLRNzTUNzIwNFOK1YlWMjEyNwKyYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    transform = Table.TransformColumns(Source,{{"Date", each try Number.FromText( _ ) otherwise _, type date }}),
    #"Changed Type" = Table.TransformColumnTypes(transform,{{"Date", type date}})
in
    #"Changed Type"

 

Or optional see the attached for the ref.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

  

View solution in original post

dax
Community Support
Community Support

Hi @Anonymous , 

It seems not to  be achieved directly, I think you could try below M code to see whether it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLRNzTUNzIwNFOK1QFyjaBcCzDX2EDf0AjEtQRzTYzMjcyQWbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([Date],"/") then 1 else 2),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Count", each [Date], type list}}),
    #"Transposed Table" = Table.Transpose(#"Grouped Rows"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"1", type any}, {"2", type any}}),
    #"Expanded 1" = Table.ExpandListColumn(#"Changed Type", "1"),
    #"Expanded 2" = Table.ExpandListColumn(#"Expanded 1", "2"),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Expanded 2", {{"1", type date}}, "aa-DJ"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"2", Int64.Type}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{{"2", type date}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type2"),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Duplicates", {}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
dax
Community Support
Community Support

Hi @Anonymous , 

It seems not to  be achieved directly, I think you could try below M code to see whether it work or not

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLRNzTUNzIwNFOK1QFyjaBcCzDX2EDf0AjEtQRzTYzMjcyQWbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([Date],"/") then 1 else 2),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Count", each [Date], type list}}),
    #"Transposed Table" = Table.Transpose(#"Grouped Rows"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"1", type any}, {"2", type any}}),
    #"Expanded 1" = Table.ExpandListColumn(#"Changed Type", "1"),
    #"Expanded 2" = Table.ExpandListColumn(#"Expanded 1", "2"),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Expanded 2", {{"1", type date}}, "aa-DJ"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type with Locale",{{"2", Int64.Type}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Changed Type1",{{"2", type date}}),
    #"Removed Duplicates" = Table.Distinct(#"Changed Type2"),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Duplicates", {}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
    #"Removed Columns"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

It is an odd one, no idea why this is happening but you can fix it by adding an extra "transform" step as per below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLRNzTUNzIwNFOK1YlWMjEyNwKyYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    transform = Table.TransformColumns(Source,{{"Date", each try Number.FromText( _ ) otherwise _, type date }}),
    #"Changed Type" = Table.TransformColumnTypes(transform,{{"Date", type date}})
in
    #"Changed Type"

 

Or optional see the attached for the ref.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors