Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
archuleta28
Resolver I
Resolver I

Subtracting two columns of same table

Hi All, 

 

I need to subtract two columns from same table. I'll try to explain with example :

 

Lets say, I have this table in which,  % of costs to sales - is a calculated column.

Formula is: % of costs to sales = DIVIDE('Table'[Costs],'Table'[Sales], 0)

 

DepartmentCostsSalesYear% of  Costs to Sales
a3409031242352021-221.09%
b34535325222022-230.65%
a24242342342352021-220.00%
b53462243242212022-230.22%
a234324423452352021-220.55%
b252513234242021-227.81%

 

When I add a matrix, it will give me:

archuleta28_0-1672402502928.png

Here, I have added year in Columns, Departments in Row and calculated % in Values.

 

Now, I need to calculate difference of % values between columns - 2022-23 and 2021-22. 

 

That means-

For deartment A,  I should get  -1.65% in new column and

For deartment B, I shuld get -6.94%.

 

Can some one help me, how can I calculate this difference? Any help is much appreciated!:)

 

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

Hi @archuleta28 

You can refer to the following column:

% of  Costs to Sales = var a=SUMMARIZE(FILTER('Table',[Year]<>"Difference"),[Department],[Costs],[Sales],[Year])
var _current_=SUMX(FILTER(a,[Department]=EARLIER('Table'[Department])&&[Year]=MAXX(a,[Year])),DIVIDE([Costs],[Sales]))
var _last=SUMX(FILTER(a,[Department]=EARLIER('Table'[Department])&&[Year]=MINX(a,'Table'[Year])),DIVIDE([Costs],[Sales]))
return IF('Table'[Year]="Difference",_current_-_last,DIVIDE([Costs],[Sales]))

Output:

vxinruzhumsft_0-1673249455507.png

 

Best Regards!

Yolo Zhu

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-xinruzhu-msft
Community Support
Community Support

Hi @archuleta28 

You can refer to the following column:

% of  Costs to Sales = var a=SUMMARIZE(FILTER('Table',[Year]<>"Difference"),[Department],[Costs],[Sales],[Year])
var _current_=SUMX(FILTER(a,[Department]=EARLIER('Table'[Department])&&[Year]=MAXX(a,[Year])),DIVIDE([Costs],[Sales]))
var _last=SUMX(FILTER(a,[Department]=EARLIER('Table'[Department])&&[Year]=MINX(a,'Table'[Year])),DIVIDE([Costs],[Sales]))
return IF('Table'[Year]="Difference",_current_-_last,DIVIDE([Costs],[Sales]))

Output:

vxinruzhumsft_0-1673249455507.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

FreemanZ
Super User
Super User

hi @archuleta28 

 

try to create a measure like:
Diff = 
VAR _year = MAX('Table'[Year])
VAR _py = LEFT(_year, 2)&MID(_year, 3, 2)-1&"-"&RIGHT(_year, 2)-1
VAR _value =
CALCULATE([% of costs to sales],  'Table'[Year] = _py)
RETURN
[% of costs to sales] - _value

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.