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
cosminc
Post Partisan
Post Partisan

same months comparison over the years - DAX

Hi

i need to buid a graph with for last 3 years (2019 inclusive)

what expression do i need to obtain comparable data (same months) - if i have data on 2019 for jan & feb also 2017 and 2018 have to be only for jan&feb

i use a calendar (1 jan 2017 till 31 dec 2019) connected with the data base

 

let's take a simple example

salesman    sales  year  month

 

YTD = calculate(sum(Source[Sales]),Source[MonthNo]<=2)
but 2 need to be built as a max month from max year from data base(not max month for each salesman) 
 
thanks!
Cosmin
1 ACCEPTED SOLUTION
ElenaN
Resolver V
Resolver V

Hello,

 

Would this help?

 

Measure 4 = 
VAR MaxYear = CALCULATE(MAX(Table5[Year]), ALL(Table5))
VAR MaxMonth = CALCULATE(MAX(Table5[Month]), Table5[Year] = MaxYear)
RETURN
CALCULATE(SUM(Table5[Sales]), FILTER(Table5, Table5[Month] <= MaxMonth && Table5[Year] >= MaxYear - 2))

Regards,

ElenaN

View solution in original post

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi, @cosminc 

You could try this measure:

Measure = VAR MaxYear = CALCULATE(MAX('Date'[Year]), ALLSELECTED('Date'))
VAR MaxMonth = CALCULATE(MAX('Date'[Month]), FILTER(ALLSELECTED('Date'),'Date'[Year] = MaxYear))
return
CALCULATE(SUM(Table1[Qty]), FILTER('Date', 'Date'[Month] <= MaxMonth&&'Date'[Year]>=MaxYear-2))

Result:

13.JPG

By the way, if you don't select any value in silcer, it will return all the data.

and for ElenaN formula if you use slicer only filter two years data, it will return blank value.

 

Best Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ElenaN
Resolver V
Resolver V

Hello,

 

Would this help?

 

Measure 4 = 
VAR MaxYear = CALCULATE(MAX(Table5[Year]), ALL(Table5))
VAR MaxMonth = CALCULATE(MAX(Table5[Month]), Table5[Year] = MaxYear)
RETURN
CALCULATE(SUM(Table5[Sales]), FILTER(Table5, Table5[Month] <= MaxMonth && Table5[Year] >= MaxYear - 2))

Regards,

ElenaN

Hi and thanks for your help

 
 
 

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.