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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Cannot convert value " of type text to date

Hi PBI Heroes,

 

I don't understand why I am getting error on the below measure when it could work on other dimensions coming from the same table at the other charts but not the last one. The relationships and link with my Calendar table shouldn't be an issue since other charts are working.

 

Shao_1-1689834545841.png

 

My measure is expressed as below:

 

LY Prev Mth =
Var MaxDate = MAX('Calendar'[Date])
Var EndDate = FORMAT(EOMONTH(MaxDate , -13) , "MM/DD/YYYY")
Var StartDate = DATE(YEAR(MaxDate)-1,MONTH(MaxDate)-1,1)
Var Final = CALCULATE(SUM('Dimensions'[QTY]), DATESBETWEEN('Calendar'[Date],StartDate,EndDate))
 
return Final

 

I read through a few similar threads but the situation seems different.

Appreciate some insights on this. Thank you!!

 

Regards

ShaoPBI help.PNG

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You're using the FORMAT function, which returns text not a date. Try

LY Prev Mth =
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR EndDate =
    EOMONTH ( MaxDate, -13 )
VAR StartDate =
    DATE ( YEAR ( MaxDate ) - 1, MONTH ( MaxDate ) - 1, 1 )
VAR Final =
    CALCULATE (
        SUM ( 'Dimensions'[QTY] ),
        DATESBETWEEN ( 'Calendar'[Date], StartDate, EndDate )
    )
RETURN
    Final

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You're using the FORMAT function, which returns text not a date. Try

LY Prev Mth =
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR EndDate =
    EOMONTH ( MaxDate, -13 )
VAR StartDate =
    DATE ( YEAR ( MaxDate ) - 1, MONTH ( MaxDate ) - 1, 1 )
VAR Final =
    CALCULATE (
        SUM ( 'Dimensions'[QTY] ),
        DATESBETWEEN ( 'Calendar'[Date], StartDate, EndDate )
    )
RETURN
    Final
Anonymous
Not applicable

Hi Johnt75

 

Thank you. It works!

 

However just for my understanding, why are the other charts able to work if the format function returns text?

 

Regards

Shao

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors