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
lux4545
Frequent Visitor

Find variance between selected quarter and the previous quarters

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

lux4545_0-1701892045272.png

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: 

lux4545_1-1701892345110.png

 

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

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])) 

vyangliumsft_0-1702264299413.png

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:

vyangliumsft_1-1702264299414.png

 

 

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

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

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])) 

vyangliumsft_0-1702264299413.png

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:

vyangliumsft_1-1702264299414.png

 

 

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

Thank you for taking the time to 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.