Forum Discussion
Peter_23
Advocate V
2 years agoComparing two periods
Hi Power Bi users, I would like a measure to compare two periods at least, e.g. Feb23 vs Feb22, Apr23 vs Apr22, but sometimes it could be Feb23 vs Feb20, in case there is not data in 22,21.. so I...
Anonymous
2 years agoNot applicable
Thanks for the reply from danextian , please allow me to provide another insight:
Hi Peter_23 ,
I created some data:
Here are the steps you can follow:
1. Create measure.
Measure =
var _minmonth=MINX(ALLSELECTED('Table'),[MonthYear])
var _maxmonth=MAXX(ALLSELECTED('Table'),[MonthYear])
var _minmonthdate=
MINX(FILTER(ALL('Table'),'Table'[MonthYear]=_minmonth),[Date]) //2022.2.1
var _maxmonthdate=
MAXX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonth),[Date]) //2023.2.3
var _maxmonthnotblank=
MAXX(
FILTER(ALL('Table'),'Table'[Date]<=_maxmonthdate&&[Amount]<>BLANK()&&MONTH([Date])=MONTH(_maxmonthdate)),[MonthYear]) // Feb23
var _date=
MINX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonthnotblank),[Date])
var _minmonthnotblank=
MAXX(
FILTER(ALL('Table'),'Table'[Date]<_date&&[Amount]<>BLANK()&&MONTH([Date])=MONTH(_minmonthdate)),[MonthYear]) // Feb23
return
SUMX(FILTER(ALL('Table'),'Table'[MonthYear]=_maxmonth),[Amount]) - SUMX(FILTER(ALL('Table'),'Table'[MonthYear]=_minmonthnotblank),[Amount])
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly