Forum Discussion
Help with comparting data dates
- 7 years ago
Hi Anonymous
The formula in your lastest post is correct to solve this problem.
So far, it is a useful workaround for your problem.
The penultimate one shows a incorrect formula.
MinDate =
CALCULATE (
MIN ( 'Table'[Full Date] ),
FILTER ( 'Table', 'Table'[Measure Version] = "Actual" ),
FILTER ( 'Table', 'Table'[Full Date] = YEAR ( 2018 ) ) //incorrect
)Please see reference how to use "calculate" with "filter"
https://www.sqlbi.com/articles/filter-arguments-in-calculate/
If the formula is used in a measure, you could use the following instead.
YTD Plan = VAR TableMaxDate = CALCULATE ( MAX ( 'Table'[Full Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Measure Version] = "Actual" ) ) VAR MinDate = CALCULATE ( MIN ( 'Table'[Full Date] ), FILTER ( ALL ( 'Table' ), 'Table'[Measure Version] = "Actual" && YEAR ( 'Table'[Full Date] ) = 2018 //from the information, it seems it is no
need to add this part, if so,
you could delete this part ) ) RETURN CALCULATE ( SUM ( 'Table'[GM] ), FILTER ( 'Table', 'Table'[Measure Version] = "Plan" ), DATESBETWEEN ( DIM_Date[Date], MinDate, TableMaxDate ) )Best Regards
Maggie
Hi v-juanli-msft and Anonymous
I have been trying to refactor the RF and Plan measures to fit this new way of working into it but it seems not to work.
YTD Plan =
VAR TableMaxDate=
CALCULATE ( MAX ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual" ) )
VAR MinDate=
CALCULATE ( MIN ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual"),FILTER('Table','Table'[Full Date]=YEAR(2018)))
RETURN
CALCULATE (
Sum ('Table'[GM]), FILTER('Table','Table'[Measure Version]="Plan" ),DATESBETWEEN (DIM_Date[Date], MinDate , TableMaxDate
))I think it does not like the MinDate, as when I try to create a single Measure to see if this works it is blank.
Min =
Var tmax = CALCULATE ( MAX ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual"))
Return
CALCULATE ( MIN ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual"),FILTER('Table','Table'[Full Date]=YEAR(tmax))
)Thanks
Ok, I have done the below;
Max Year Number = CALCULATE ( MAX ( 'Table'[Year] ), FILTER('Table','Table'[Measure Version]="Actual"))
YTD Plan =
VAR TableMaxDate=
CALCULATE ( MAX ( 'Table'[Full Date] ), FILTER('Table','Table'[Measure Version]="Actual" ) )
RETURN
CALCULATE (
Sum ('Table'[GM]), FILTER('Table','Table'[Measure Version]="Plan" ),DATESBETWEEN (DIM_Date[Date], DATE([Max Year Number],1,1) , TableMaxDate
))It seems a little bit messy way of doing things but it got the right answer!
Do you think there is a better way to do this?
Thanks