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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Calculation error in measure comparing values of different types

Hello - I am trying to create a measure that will be used in a trailing 12 months bar chart where the left-most bar in the chart is the the oldest date and the farthest right bar is the current month. to create this I made the below measure where I am filtering the sum of my total sales by those in the last 12 months. To do this I created a disconnected date table named 'date' both the [End of Month Date] columns are formatted as "date" types and have been automatically turned into a date heirarchy by Power BI. The measure does not display an error until I add it to my visual where it says: "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." 

 

I tried adding the .[Date] to the end of the [End of Month Date] fields in the measure and it did not work either. Do I need to convert all the dates to text for some reason? Thank you!!

 

TTM_Sales =
Var CurrentDate = Max('Date'[End of Month Date])
Var previousdate = CurrentDate - 365
Return
CALCULATE(
Sum('Shipment Query'[Total Revenue]),
Filter(
'Shipment Query',
'Shipment Query'[End of Month Date] >= previousdate & 'Shipment Query'[End of Month Date] <= CurrentDate
         )
)
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

Try this one, please. you have to add two &&

TTM_Sales =
VAR CurrentDate =
    MAX ( 'Date'[End of Month Date] )
VAR previousdate = CurrentDate - 365
RETURN
    CALCULATE (
        SUM ( 'Shipment Query'[Total Revenue] ),
        FILTER (
            'Shipment Query',
            'Shipment Query'[End of Month Date] >= previousdate && 
            'Shipment Query'[End of Month Date] <= CurrentDate
        )
    )


You can use one of the Time Intelligence  functions like:

CALCULATE (
    [Sales Amount],
    DATESINPERIOD (
        'Date'[Date],
        MAX ( 'Date'[Date] ),
        -1,
        YEAR
    )
)




 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@Anonymous 

Try this one, please. you have to add two &&

TTM_Sales =
VAR CurrentDate =
    MAX ( 'Date'[End of Month Date] )
VAR previousdate = CurrentDate - 365
RETURN
    CALCULATE (
        SUM ( 'Shipment Query'[Total Revenue] ),
        FILTER (
            'Shipment Query',
            'Shipment Query'[End of Month Date] >= previousdate && 
            'Shipment Query'[End of Month Date] <= CurrentDate
        )
    )


You can use one of the Time Intelligence  functions like:

CALCULATE (
    [Sales Amount],
    DATESINPERIOD (
        'Date'[Date],
        MAX ( 'Date'[Date] ),
        -1,
        YEAR
    )
)




 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

That fixed it! Thank you for the quick and helpful response!!!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors