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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
CMOLINA
Frequent Visitor

Compare Year with Numer or Date

hello, I need your help:

I have this Calculated Field: 

  • CALCULATE(Sales[Sales USD],FILTER('CALENDAR', 'CALENDAR'[Year]=2022))
CMOLINA_0-1665541853723.png this is OK

 

but when I change for that:
  • Sales CY =
  • var CY=  year(LASTDATE('CALENDAR'[Date]))
  • Return
  • CALCULATE(Sales[Sales USD],FILTER('CALENDAR', 'CALENDAR'[Year]=CY))

CMOLINA_1-1665541945846.png I need only the sales for the current year

 

Why PBi doing this? What is the correct solution? 😞

Thanks Team

1 ACCEPTED SOLUTION
lukiz84
Memorable Member
Memorable Member

LASTDATE is calculated per row so for example in the row with 2021-10 the last year is 2021. To make it work the way you want it you have to write it like this:

 

Sales CY = 
   var CY = CALCULATE(
      YEAR(LASTDATE('Calendar'[Date])),
      ALL(Calendar)
   )
   RETURN
      CALCULATE(
         SUM(Sales[Sales USD]),
         Calendar[Year] = CY
      )
   

View solution in original post

2 REPLIES 2
lukiz84
Memorable Member
Memorable Member

LASTDATE is calculated per row so for example in the row with 2021-10 the last year is 2021. To make it work the way you want it you have to write it like this:

 

Sales CY = 
   var CY = CALCULATE(
      YEAR(LASTDATE('Calendar'[Date])),
      ALL(Calendar)
   )
   RETURN
      CALCULATE(
         SUM(Sales[Sales USD]),
         Calendar[Year] = CY
      )
   
Ashish_Mathur
Super User
Super User

Hi,

Assuming you already have a Date column in your Data Table, create a Calendar Table with calculated column formulas for Year, Month name and Month number.  Sort the Month name column by the Month number column.  Create a relationship (Many to One and Single) from the Date column of your Data Table to the Date column of the Calendar Table.  Create a slicer of Year (dragged from the Calendar Table) and select 2022.  Write this measure

Total sales = sum(Sales[Sales USD])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.