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
MojoGene
Post Patron
Post Patron

Anchor Date - reference to prior year

After setting an anchor date of 12/31/2018 for a particular report on income and expenses, a field referencing the "prior year" did not work as expected. The time dimension in the measure looks like this:

 

Date[YearKey]=YEAR(TODAY()-1)

The function TODAY, however, still renders the current year (2019) despite the anchor date setting (which is logical, no doubt), so this time referene still gives 2018 values. 

 

This measure gives me the year I am looking for:

 

Last Year Prior to Anchor Year = YEAR(LASTDATE(Date[DateKey]))

LASTDATE picks up the anchor date, but when I use it in a measure to calculate income/expenses  (

Date[YearKey]=[Last Year Prior to Anchor Year]), I get an error as follows:

  

A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 Any help appreciated.

1 ACCEPTED SOLUTION

@MojoGene,

 

Modify your measure like below and check if it can meet your requirement:

 

Income =
CALCULATE ( [Income], SAMEPERIODLASTYEAR ( Table_BasicCalendarUS[DateKey] ) )

Regards,

Jimmy Tao

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Greg:

 

I looked at your very interesting TITHW solution. It's a lot for us ordinary folks to get our heads around. I'll have to spend some time with it.

 

In the meanwhile, any thought on why something like this does not work:

Income =
CALCULATE (
    [Income],
    DATESBETWEEN (
        Table_BasicCalendarUS[DateKey],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( Table_BasicCalendarUS[DateKey] ) ) ),
        LASTDATE ( Table_BasicCalendarUS[DateKey] )
    )
)

This measure is on a page where the anchor date is set to 12/31/2018 and LASTDATE returns 12/31/2018 as a result. The intent here is to show the 2017 results, but it is clearly not working as intended.

@MojoGene,

 

Modify your measure like below and check if it can meet your requirement:

 

Income =
CALCULATE ( [Income], SAMEPERIODLASTYEAR ( Table_BasicCalendarUS[DateKey] ) )

Regards,

Jimmy Tao

Jimmy:

 

Thanks very much. Worked perfectly.

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.