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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors