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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
manoj_0911
Post Patron
Post Patron

Alternatives to FORMAT Function for Date-Time Formatting in DirectQuery Mode

Hi,

 

I’m currently working with a set of reports that use **Import mode**, but I want to convert these to **DirectQuery mode** for testing purposes. However, I’m encountering issues with date-time formatting when I switch to DirectQuery.

 

In Import mode, I used the `FORMAT` function in calculated columns to format date-time values, but in DirectQuery, I receive the following error:

 

> *"Function 'FORMAT' is not allowed as part of calculated column DAX expressions on DirectQuery models."*

 

Here are the calculated columns I’m attempting:

1. **Date:** `FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "yyyy-MM-dd")`
2. **Hour:** `FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "yyyy-MM-dd HH:00:00")`
3. **Month:** `FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "MMMM yyyy")`
4. **Subhour:** `FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "yyyy-MM-dd HH") & IF(MINUTE('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]) < 30, ":00:00", ":30:00")`

 

Since `FORMAT` isn’t supported in DirectQuery calculated columns, I’d like advice on any workarounds.

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @manoj_0911 

 

Thank you very much Ritaf1983 and Kedar_Pande for your prompt reply.

 

Pls try this:

 

vnuocmsft_1-1730359926205.png

 

Here's some dummy data

 

vnuocmsft_2-1730360018743.png

 

Create a measure.

 

Measure = 
VAR _date = SELECTEDVALUE('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE])
RETURN
TIMEVALUE(_date)

 

Here is the result.

 

vnuocmsft_3-1730360096795.png

 

Try to convert a text type to a date/time type in DirectQuery mode using TIMEVALUE().

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

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

3 REPLIES 3
Anonymous
Not applicable

Hi @manoj_0911 

 

Thank you very much Ritaf1983 and Kedar_Pande for your prompt reply.

 

Pls try this:

 

vnuocmsft_1-1730359926205.png

 

Here's some dummy data

 

vnuocmsft_2-1730360018743.png

 

Create a measure.

 

Measure = 
VAR _date = SELECTEDVALUE('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE])
RETURN
TIMEVALUE(_date)

 

Here is the result.

 

vnuocmsft_3-1730360096795.png

 

Try to convert a text type to a date/time type in DirectQuery mode using TIMEVALUE().

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

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

 

 

 

Kedar_Pande
Super User
Super User

@manoj_0911 

Consider creating date-time columns in your source database to achieve the formatting before it’s imported into Power BI. This approach avoids the need for complex DAX altogether, which is especially useful in DirectQuery mode.

 

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Ritaf1983
Super User
Super User

Hi @manoj_0911 

When switching from Import mode to DirectQuery, Power BI restricts certain functions like FORMAT in calculated columns. Here are some workarounds for each case, focusing on using FORMAT alternatives or moving these transformations to Power Query or your source database.

Workarounds:
Date Format: Instead of FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "yyyy-MM-dd"), you can use:

DAX
Copy code
YEAR('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]) & "-" &
RIGHT("0" & MONTH('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & "-" &
RIGHT("0" & DAY('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2)
This concatenates year, month, and day as strings without FORMAT.

Hour Format: Replace FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "yyyy-MM-dd HH:00:00") with:

DAX
YEAR('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]) & "-" &
RIGHT("0" & MONTH('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & "-" &
RIGHT("0" & DAY('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & " " &
RIGHT("0" & HOUR('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & ":00:00"
Month Format: For the month format FORMAT('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "MMMM yyyy"), one workaround is to use:

DAX
FORMAT( 'QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE], "MMMM" ) & " " &
YEAR( 'QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE] )
Alternatively, move this to Power Query or your source database if the above approach doesn’t work due to DirectQuery restrictions.

Subhour Format: To replace FORMAT for subhour, you can use:

DAX
YEAR('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]) & "-" &
RIGHT("0" & MONTH('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & "-" &
RIGHT("0" & DAY('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) & " " &
RIGHT("0" & HOUR('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]), 2) &
IF(MINUTE('QUEUE_ABN_SUBHOUR_V'[IXN_SUBHOUR_DATE]) < 30, ":00:00", ":30:00")
Alternative Approach: Using Power Query or the Source Database
For better performance and less complexity, consider pushing these transformations to Power Query or directly to your source database:

In Power Query, you can format dates and times using M language without DirectQuery limitations.
In the source database, use SQL formatting functions (like CONVERT or FORMAT) to handle date-time formatting before it reaches Power BI

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors