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

Date formula does not work, but if I input single digits it works

In a measure I am using, I create a date as follows:

DATE(
    YEAR(MAX('Calendar create Date'[Date]))-1,
    MONTH(MAX('Calendar create Date'[Date])),
    DAY(MAX('Calendar create Date'[Date]))
)

Which is supposed to give me the max of the calendar date of last year. This works, tried both in cards and in other measures. However, when I put it on a trend line graph it doesn't work and gives me this error:

ale_PBi_0-1674549026050.png

I don't understand what I'm doing wrong here. If I do say DATE(2021,10,17) it works perfectly fine with all the rest of the measure calculations as well



 

6 REPLIES 6
FreemanZ
Super User
Super User

hi @Anonymous 

try to write the measure like this:

 

MaxDateLY = 
VAR _MaxYear = 
YEAR( 
    MAXX(
        ALL('Calendar create Date'[Date]),
        'Calendar create Date'[Date]
    )
)
RETURN
MAXX(
    FILTER(
        ALL('Calendar create Date'[Date]), 
        YEAR('Calendar create Date'[Date]) =_MaxYear-1 
    ),
    'Calendar create Date'[Date]
)

 

 

tried and it worked like this:

sample data:

FreemanZ_2-1674565050388.png

 

FreemanZ_0-1674564913951.png

it is supposed to ignore any filter context, like:

FreemanZ_1-1674564945619.png

Thank you so much for this. It works perfectly, and I'm trying to understand especially why you decided to use MAXX here, can you help me understand your thought process?

 

johnt75
Super User
Super User

Use Performance Analyzer to copy the query generated by Power BI for the visual and paste it into DAX Studio. Change the SUMMARIZECOLUMNS to add a new column which shows 

MAX('Calendar create Date'[Date])

and run the query, sorted by the new column in descending order. That should show if you have unexpectedly high values in the date.

Anonymous
Not applicable

I don't see any suspiciously high values. The formula still works like this

can you share a PBIX file with any confidential info removed ?

Anonymous
Not applicable

Hmm the PBIX is way too big, and I can't possibly cancel out all the confidential info without leaving some behind. I'm afraid I can't share it

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.

Top Solution Authors