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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Pikachu-Power
Impactful Individual
Impactful Individual

Difference of two columns for categories

Hi all,
 
I count the entries in two columns in the same table:
 
CountX = CALCULATE(COUNT(Tabel1[ColumnX]), FILTER(Tabel1, Tabel1[ColumnX] <> Tabel1[ColumnY]))
CountY = CALCULATE(COUNT(Tabel1[ColumnY]), FILTER(Tabel1, Tabel1[ColumnX] <> Tabel1[ColumnY]))
 
The result I get is:
 
1.PNG
 
What I want is the difference of equal categories. For example A from column X minus A from ColumnY = 11. See also picture above.
 
Some ideas? 
 
Many thanks.
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @Pikachu-Power 

Try this measure:

 

 

 

Difference = 
Var _Item = FIRSTNONBLANK('Table'[ColumnX],"")
Var _ValueX = sumx(filter('Table','Table'[ColumnX]=_Item),'Table'[ValueX])
Var _ValueY = sumx(filter(all('Table'),'Table'[ColumnY]=_Item),'Table'[ValueY])
return
_ValueX-_ValueY

 

 

 

The output will be as follow:

 

VahidDM_0-1629898727602.png

Table I used in Power BI:

VahidDM_0-1629898864431.png

 

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_1-1629898779406.png !!

 

View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

Hi @Pikachu-Power 

Try this measure:

 

 

 

Difference = 
Var _Item = FIRSTNONBLANK('Table'[ColumnX],"")
Var _ValueX = sumx(filter('Table','Table'[ColumnX]=_Item),'Table'[ValueX])
Var _ValueY = sumx(filter(all('Table'),'Table'[ColumnY]=_Item),'Table'[ValueY])
return
_ValueX-_ValueY

 

 

 

The output will be as follow:

 

VahidDM_0-1629898727602.png

Table I used in Power BI:

VahidDM_0-1629898864431.png

 

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_1-1629898779406.png !!

 

Both cases dont work yet. I suppose because i also have filtered Tabel1[Year] = 2019 that get ignored through the ALL command?

 

@Vahid With Table[ValueX] you mean Table[CountX]? My measure before?

@VahidDM

I modivied ALL(Table) to ALLEXCEPT(Table, Table(Year)) and it seems to work 🙂

ryan_mayu
Super User
Super User

@Pikachu-Power 

maybe try

DIFF = COUNT(Tabel1[ColumnX])- CALCULATE(COUNT(Tabel1[ColumnY]), FILTER(ALL(Tabel1), Tabel1[ColumnY] =MAX(Tabel1[ColumnX]))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors