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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
MrMike
Helper II
Helper II

Power Query M change data type variable to data type date

What is the syntax in (Power Query M / DAX) change data type variable to data type date? I tried using FORMAT but I get error message shown below.

 

Flag1 =
var DateRange = SELECTCOLUMNS(ALLSELECTED('date'),"Date", [Date])
return
IF(MAX('Table'[Start Date]) >= FORMAT(DateRange, "General Date") & MAX('Table'[End Date]) <= FORMAT(DateRange, "General Date"), 1, 0)
 

Error Message:

MdxScript(Model) (7, 4) Calculation error in measure 'Table'[Flag1]: DAX comparison operations do not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

 

1 ACCEPTED SOLUTION

Hi, @MrMike 

 

I am sorry for the late reply. I modify the data based on your sample data. The pbix file is attached in the end.

Table(Dates are in mm/dd/yyyy format):

a1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create a measure as below.

Visual Control = 
var _start = SELECTEDVALUE('Table'[StartDate])
var _end = SELECTEDVALUE('Table'[EndDate])
var _min = MIN('Calendar'[Date])
var _max = MAX('Calendar'[Date])
var re = 
IF(
    NOT(
        OR(
            _start>_max,
            _end<_min
        )
    ),
    1,0
)
return
re


Finally you need to put the measure in the visual level filter and use 'Date' column from 'Calendar' table to filter the result.

a2.png

 

Best Regards

Allan

 

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

5 REPLIES 5
v-alq-msft
Community Support
Community Support

Hi, @MrMike 

 

You may create a measure as below to see it works.

Flag1 =
VAR DateRange =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    IF (
        MAX ( 'Table'[Start Date] ) >= DateRange
            && MAX ( 'Table'[End Date] ) <= DateRange,
        1,
        0
    )

 

Best Regards

Allan

 

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

I tried your code and got this error: 

"MdxScript(Model) (9, 9) Calculation error in measure 'Course'[IsCourseWithInDateRange]: DAX comparison operations do not support comparing values of type Text with values of type Date. Consider using the VALUE or FORMAT function to convert one of the values."

 

So I tried using VALUE and I tried FORMAT and both have me syntex errors.

mahoneypat
Microsoft Employee
Microsoft Employee

SELECTCOLUMNS returns a table so you can't use it inside FORMAT.  Please show some example data and the result you are looking for.

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


I created a sample power bi report. I don't see how to attach .pbix file to this thread.

So here is the example of data and result.

CourseNameStartDateEndDate

Math1/1/20212/1/2021
Science2/1/20213/1/2021
English3/1/20214/1/2021
Art4/1/20215/1/2021
Gym1/1/202112/1/2021

 

Select a start and end date and all course that are with in that range should show. For example 1/1/2021 to 2/1/2021 should show Math, Science and Gym.

 

Hi, @MrMike 

 

I am sorry for the late reply. I modify the data based on your sample data. The pbix file is attached in the end.

Table(Dates are in mm/dd/yyyy format):

a1.png

 

Calendar(a calculated table):

Calendar = CALENDARAUTO()

 

There is no relationship between two tables. You may create a measure as below.

Visual Control = 
var _start = SELECTEDVALUE('Table'[StartDate])
var _end = SELECTEDVALUE('Table'[EndDate])
var _min = MIN('Calendar'[Date])
var _max = MAX('Calendar'[Date])
var re = 
IF(
    NOT(
        OR(
            _start>_max,
            _end<_min
        )
    ),
    1,0
)
return
re


Finally you need to put the measure in the visual level filter and use 'Date' column from 'Calendar' table to filter the result.

a2.png

 

Best Regards

Allan

 

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors