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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
lt79_Pax
Helper II
Helper II

How to convert date to datetime for incremental refresh

Dear Power BI Representative,

I have a dateset where the date key was stored as date however for an incremental refresh the format needs to be set to date/time.  When I try to change the type of the field to date/time I receive an error message indicating 'Unable to confirm if the M query can be folded. It is not recommended to use incremental refresh with non-foldable queries' since you cannot use a change data type when invoking an incremental refresh.  Therefore how do I convert a date key to datetime without doing a change type query?  Does anyone know the function for converting a date field to datetime in M code in order to invoke a function?  This differs from converting an integer to date/time.  Here the date is set to date and I need to convert it to date/time.  The images below illustrate the error when trying to change the type on the date key.  Please advise.

 

Thank you.

lt79_Pax_0-1637612896108.pnglt79_Pax_1-1637612945385.png

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @lt79_Pax ,

 

The data type of the RangeStart and RangeEnd parameters must be of date/time data type. However, for many data sources, tables don't have a column of date/time data type but instead have a date column of integer surrogate keys in the form of yyyymmdd. You can create a function that converts the date/time value in the parameters to match the integer surrogate key of the data source table. The function is then called in a filter step. This step is required if the data source table contains only a surrogate key as integer data type.

Details: https://docs.microsoft.com/en-us/power-bi/connect-data/incremental-refresh-configure#convert-datetim... 

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @lt79_Pax ,

 

The data type of the RangeStart and RangeEnd parameters must be of date/time data type. However, for many data sources, tables don't have a column of date/time data type but instead have a date column of integer surrogate keys in the form of yyyymmdd. You can create a function that converts the date/time value in the parameters to match the integer surrogate key of the data source table. The function is then called in a filter step. This step is required if the data source table contains only a surrogate key as integer data type.

Details: https://docs.microsoft.com/en-us/power-bi/connect-data/incremental-refresh-configure#convert-datetim... 

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
AlexisOlson
Super User
Super User

The function DateTime.From should work to convert date to datetime data type.

Hi AlexisOlson,

Thank you for the function however I am not familiar with M code.  How would I use this function for the converting a field in preparation for an incremental refresh?   If my column field name was InvoiceDate set as a date.  How would this function look?  DateTime.From(InvoiceDate)?  When I use this I receive an error message.  It also created a change type which will not work with an incremental refresh.  Therefore, how would I use this function?  What would be the syntax if the field InvoiceDate is of type date and I need to convert it to date/time without creating a column but invoking a function.   = (x as date)=>Datetime.from(x).  If I try this I also get another error message.  I am afraid I just do not understand how this function can be used.  Please advise.

 

Thank you.

 

lt79_Pax_1-1637618571377.png

 

lt79_Pax_0-1637618300374.png

 

Note that M is case-sensitive. That is, "DateTime.From" is not the same as "datetime.from" and the latter won't work.

 

It may work better for you to go the other way and convert RangeStart and RangeEnd to date type in your filter step. Try this step instead of transforming your column.

[Invoice Date Key] > Date.From(RangeStart) and [Invoice Date Key] <= Date.From(RangeEnd)

 

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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