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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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...



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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