Skip to content

Add a universal datatype correction function #1

@MattRudy

Description

@MattRudy

Problem

For columns with unknown or variable datatypes, it is hard to know the right type conversion method. Using the wrong conversion function in Power Query will cause errors on data load and prevent refreshes from succeeding.

i.e. if you want to compare dates, but don't know what format your input columns is contained in, you can't write a comparison without a risk of errors.

Text to Date is Date.FromText()
DateTime to Date is DateTime.Date()
Number (i.e. Unix/Epoch time) to Date requires significant parsing

Proposed Function

Types can be discovered using Value.Type(), and can be compared using the syntax '[Input] is text'.
A function like "OverrideType( [Input] , text , (errorVal) )' would take the value from the first argument and try to convert it to the type specified in the second argument. Cases where a translation could not be done would return the option value in the third parameter, such as null, a blank text string, or an error statement.

More information about Power Query M types can be found in the documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions