Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DAX for SAMEPERIODLASTYEAR

Hi ,

 

I am trying to calculate Previous years value using SAMEPERIODLASTYEAR function in DAX. But i eed the data to be filtered based on current year's record. We have a CompFlag column in the table. So basically, I want a measure that when I enter date as 2019-01-15 and the CompFlag=1(meaning there is data for 2018-01-15) returns data for 2018-01-15. But when i apply the below measure, it returns me data from previous year but it looks at the CompFlag from last year as well. So lets say that for 2019-01-15 has some data and CompFlag=1 and thereis data for 2018-01-15 and CompFlag for that date(2018) is 0, then I would expect some data to be returend but instead ot filters out that record coz it looking at the wrong CompFlag.

 

Here is the measure:

CALCULATE(SUMX(FILTER('1 - Table1', '1 - Table1[ComparableFlag] = TRUE),'1 - Table1'[SomeValue]),SAMEPERIODLASTYEAR(Date[Date])). 

 

So my question is how can I accomplish that? Below is the expected outcome:

 

Date   Value  CompFlag

2019-01-15     $23      1

2018-01-15     11    0

 

Expected Result:  $11

Current Result: BLANK

 

Basically what I would like to do is first filter the data for allCompFlag=1 and then apply the SAMEPERIODLASTYEAR to that dataset but I dont know a way to do that like some kind of temp tables like we have in SQL. Thank you in advance for your help and suggestions. 

1 Reply