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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
viorelcazacu
Regular Visitor

Error in creating Date value

Hello,

 

I get an error when I want to create a date value with the DATE(Year, Month, Day) function.

 

The function that gives error is this: DATE([MaxDateYear],[MaxDate],1)

 

where MaxDate:=month(max(VentasSeccion[Fecha])) that should be the Month number

and MaxDateYear:=YEAR(max(VentasSeccion[Fecha])) that should be the Year number

 

I guess that those 2 measures that result in Month and Year (which are correct) does not have the format as numbers (Integers) and the Date function does not recognize them.

 

Many thanks for the support!

Viorel

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

You cannot use measures in your filter like that. Use variables.

View solution in original post

Hi @viorelcazacu ,

 

Put the 2 variables in the formula,such as below:

SalesMTD CY = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Fecha]>=DATE(YEAR(MAX('Table'[Fecha])),MONTH(MAX('Table'[Fecha])),1)&&'Table'[Fecha]<EOMONTH(MAX('Table'[Fecha]),0)))

And you will see:

v-kelly-msft_1-1616491365551.png

 

For the sample .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

An ez solution I found is to split the column by the separator "/", now u have dd mm yyyy, after that u add all of them into a new column with this "Text.PadStart(Text.From([Day]), 2, "0") & "/" & Text.PadStart(Text.From([Month]), 2, "0") & "/" & Text.From([Year])", with this u can change it into date.

lbendlin
Super User
Super User

You cannot use measures in your filter like that. Use variables.

lbendlin
Super User
Super User

Encapsulate your measure results in VALUE()

 

VALUE function (DAX) - DAX | Microsoft Docs

Hello,

 

Unfortunatedly it does not work. I tried to encapsulate the two measures in Value, nothing happens (the formula does not gives error, it just shows nothing (like there is no data)

 

MaxDate:=value(month(max(VentasSeccion[Fecha])))

MaxDateYear:=value(YEAR(max(VentasSeccion[Fecha])))

 

I even tried to put also value inside the target formula, with no result:

DATE([value(MaxDateYear]),value([MaxDate]),1)

 

The formula works only if I hard code the Year and Number:

 

SalesMTD CY:=CALCULATE(

[Total Sales],

FILTER(
ALL(DateCalendarTable[Calendar Date]),
AND(
DateCalendarTable[Calendar Date] >= DATE(2021,3,1),
DateCalendarTable[Calendar Date] <= [MaxDateSalesTbl]

)))

 

Kind regards,

Viorel

Hi @viorelcazacu ,

 

Put the 2 variables in the formula,such as below:

SalesMTD CY = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Fecha]>=DATE(YEAR(MAX('Table'[Fecha])),MONTH(MAX('Table'[Fecha])),1)&&'Table'[Fecha]<EOMONTH(MAX('Table'[Fecha]),0)))

And you will see:

v-kelly-msft_1-1616491365551.png

 

For the sample .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Dear @v-kelly-msft ,

 

Your solution works like a charm as I cannot use variables (the work Powerpivot is version 2013):

 

SalesMTD CY:=CALCULATE(

[Total Sales],

FILTER(ALL(DateCalendarTable[Calendar Date]),

DateCalendarTable[Calendar Date]>=DATE(YEAR(MAX(VentasSeccion[Fecha])),MONTH(MAX(VentasSeccion[Fecha])),1)

&&DateCalendarTable[Calendar Date]<EOMONTH(MAX(VentasSeccion[Fecha]),0))
)

 

Many thanks and kind regards,

Viorel

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.