Forum Discussion
Convert date in date type, not string
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!