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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
giuliapiazza94
Helper IV
Helper IV

Convert date in date type, not string

Hi guys,

i try to use report builder but i have some problems with data type. 

I've this query

 

giuliapiazza94_1-1730819931291.png

 

When i try to filter date (for example date >= 01/01/2024), I can't to do this because it convert data in string. In power bi the field is date type, not string.

 

giuliapiazza94_0-1730819886503.png

 

How can I convert the column in date type?

 

Thank you all 🙂

 

 

 

3 REPLIES 3
Ankur04
Resolver II
Resolver II

Hi @giuliapiazza94 ,

 

can you try using Cdate function in the expression.

 

please let me know if you need further support.

 

Thanks,

 

 

Hi, @giuliapiazza94 

Based on your information, I create a sample Table:

vyohuamsft_0-1732521504450.png

vyohuamsft_8-1732523311365.png

 

Import to the Report Builder. Then right-click dataset.

vyohuamsft_1-1732521763345.png

vyohuamsft_4-1732522068107.png

In the query designer, you can use expressions to convert strings to date types. For example, if your date string is in the format "dd/MM/yyyy", you can use the following expression:

 

CONVERT(date, [DateString], 103)

 


Here, 103 is the style code used for the UK/France date format.

Converted query:

vyohuamsft_2-1732521798001.png

 

Insert a Table visual and click Run

vyohuamsft_3-1732521853924.png

If you want to use Cdate, you can right click text, select Expression.

vyohuamsft_5-1732523029508.png

vyohuamsft_6-1732523068641.png

 

Use the following code:

=CDate(Fields!DateString.Value)

Before:

vyohuamsft_11-1732523441594.png

 

After:

vyohuamsft_9-1732523383085.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

FarhanJeelani
Solution Supplier
Solution Supplier

In Report Builder, if the date field `[Data]` is recognized as text, you can try explicitly converting it to a date format within your query or by using an expression in the filter. Here are two methods to achieve this:

 

Method 1: Modify the Query to Cast `[Data]` as a Date
If you have control over the query, try casting or converting the `[Data]` column to a date format directly in the query. The syntax will depend on your data source.

For example:
- SQL Server:

sql

SELECT
CAST([Data] AS DATE) AS [Data]
FROM
your_table



- DAX (if using Power BI):
DAX

EVALUATE
SELECTCOLUMNS(
your_table,
"Data", DATEVALUE([Data])
)



This approach ensures that `[Data]` is treated as a date field within Report Builder.

 

Method 2: Use an Expression in Report Builder to Convert Text to Date
If you cannot modify the query, use an expression in the Filter properties to convert `[Data]` to a date type before applying the filter:

 

1. In the filter properties, select `[Data]` as the Expression.
2. Change the data type to **Date/Time instead of Text.
3. In the Value field, enter your date filter in the appropriate format (e.g., `1/1/2024` or `01/01/2024` depending on your locale).

Alternatively, if you need more complex date filtering in Report Builder, you can use an expression like:
VB
=CDate(Fields!Data.Value)
This expression will convert `[Data]` to a date type, allowing you to apply date comparisons directly.

Let me know if you encounter any issues with these methods!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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