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.
I have a formula on my data that will show the last five quarters based on the current quarter selected from the slicer. I need to create a caluclation that will give me the varaince between the previous quarter and the last quarter. Below is sample data and for the image the selected quarter is 2020Q2. I would like to see 2020Q2 - 2020Q1 and 2020Q2 - 2019Q2.
The new column for 2020Q2 - 2020 Q1 would have the values:
1-2 =-1
8-9=-1
15-16=-1
Additional background the quarters are attached to an index table and the values in the table are produced by the below code to show the last five quarters from selected value:
Solved! Go to Solution.
Hi @lux4545 ,
Here are the steps you can follow:
1. Create calculated column.
Date Table =
var _table=
CALENDAR(
DATE(2019,1,1),DATE(2020,12,31))
return
ADDCOLUMNS(
_table,
"Quarter",
YEAR([Date])&"Q"&
QUARTER(
[Date]))
2. Create measure.
Measure1 =
var _select=SELECTEDVALUE('Date Table'[Quarter])
var _lastmaxdate=MINX(FILTER(ALL('Date Table'),'Date Table'[Quarter]=_select),[Date])-1
var _lastqu=MINX(FILTER(ALL('Date Table'),'Date Table'[Date]=_lastmaxdate),[Quarter])
var _current=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_select&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
var _last=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_lastqu&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
return
_current - _last
Measure2 =
var _select=SELECTEDVALUE('Date Table'[Quarter])
var _minxdate=MINX(FILTER(ALL('Date Table'),'Date Table'[Quarter]=_select),[Date])
var _lastdate=DATE(YEAR(_minxdate)-1,MONTH(_minxdate),DAY(_minxdate))
var _lastqu=MINX(FILTER(ALL('Date Table'),'Date Table'[Date]=_lastdate),[Quarter])
var _current=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_select&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
var _last=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_lastqu&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
return
_current - _last
3. 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
Hi @lux4545 ,
Here are the steps you can follow:
1. Create calculated column.
Date Table =
var _table=
CALENDAR(
DATE(2019,1,1),DATE(2020,12,31))
return
ADDCOLUMNS(
_table,
"Quarter",
YEAR([Date])&"Q"&
QUARTER(
[Date]))
2. Create measure.
Measure1 =
var _select=SELECTEDVALUE('Date Table'[Quarter])
var _lastmaxdate=MINX(FILTER(ALL('Date Table'),'Date Table'[Quarter]=_select),[Date])-1
var _lastqu=MINX(FILTER(ALL('Date Table'),'Date Table'[Date]=_lastmaxdate),[Quarter])
var _current=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_select&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
var _last=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_lastqu&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
return
_current - _last
Measure2 =
var _select=SELECTEDVALUE('Date Table'[Quarter])
var _minxdate=MINX(FILTER(ALL('Date Table'),'Date Table'[Quarter]=_select),[Date])
var _lastdate=DATE(YEAR(_minxdate)-1,MONTH(_minxdate),DAY(_minxdate))
var _lastqu=MINX(FILTER(ALL('Date Table'),'Date Table'[Date]=_lastdate),[Quarter])
var _current=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_select&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
var _last=
SUMX(FILTER(ALL('Main Table'),YEAR('Main Table'[Date])&"Q"&QUARTER('Main Table'[Date])=_lastqu&&'Main Table'[Company]=MAX('Main Table'[Company])),[Amount])
return
_current - _last
3. 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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
97 | |
95 | |
76 | |
72 | |
65 |
User | Count |
---|---|
140 | |
109 | |
103 | |
82 | |
73 |