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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

MDXScript(Model) calculation Error

I am trying to create a simple moving average for my area chart and I keep getting the following error. "A column specified in the call to function 'datesbetween' is not of type date. this is not supported."

 

Here is my function

AVERAGEX(
DATESBETWEEN('Data (10)'[RequestDateRaised - Copy], MAX('Data (10)'[RequestDateRaised - Copy]), max('Data (10)'[RequestDateRaised - Copy])),
CALCULATE(sum('Data (10)'[Count]))
)
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I suggest you to create a DimDate table with continuous date if you want to use DATESBETWEEN() which is a time intelligence function.

Try CALENDAR() or CALENDARAUTO().

DimDate = ADDCOLUMNS( CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]))

My Sample:

RicoZhou_0-1659424921081.png

Measure:

Measure = 
AVERAGEX(
DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),MAX(DimDate[Date])),
CALCULATE(sum('Data (10)'[Count]))
)

Then add Year/Month columns into Axis. Result is as below.

RicoZhou_1-1659424940160.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Hello, that still didn't work. I did not get an error in DAX but when I input the measure in my chart it did not add a simple moving average (SMA). 

Hi @Anonymous ,

 

I suggest you to create a DimDate table with continuous date if you want to use DATESBETWEEN() which is a time intelligence function.

Try CALENDAR() or CALENDARAUTO().

DimDate = ADDCOLUMNS( CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]))

My Sample:

RicoZhou_0-1659424921081.png

Measure:

Measure = 
AVERAGEX(
DATESBETWEEN(DimDate[Date],MIN(DimDate[Date]),MAX(DimDate[Date])),
CALCULATE(sum('Data (10)'[Count]))
)

Then add Year/Month columns into Axis. Result is as below.

RicoZhou_1-1659424940160.png

 

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@Anonymous , Make sure the data type is date, why both are max

always use date table

try like

 


CALCULATE
( AVERAGEX(values('Data (10)'[RequestDateRaised - Copy]),
CALCULATE(sum('Data (10)'[Count]))
),DATESBETWEEN('Date'[Date],min('Date'[Date]),max('Date'[Date])))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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