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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
rnola16
Advocate II
Advocate II

Sum on Case Statement on a column

I'm trying to use this SQL statement in DAX func.

 

=Sum( CASE when tablename.colname in ('a','b') then -1

                      when tablename.colname in ('c','d') then 0

                      when tablename.colname in ('e','f') then 1

             else 0 

             END)

 

which is an ideal func to use CALCULATE() or SWITCH() ?

 

Thanks. 

1 ACCEPTED SOLUTION

Works for me 

kushanNa_1-1740710882262.png

 

maybe you are trying to use DAX code in M (Power Query) then it will throw an error on 'in' ? if that's the case then DAX functions cannot be used in M query 

 

View solution in original post

5 REPLIES 5
rnola16
Advocate II
Advocate II

Thank you, that worked. The mistake I did, i tried creating a new column in the power query and didnt work, instead created a new measure on the report page.

Anonymous
Not applicable

Hi @rnola16 ,

 

If the problem has been solved, please accept as solution the replies you find helpful.

 

 

Best regards,

Mengmeng Li

rnola16
Advocate II
Advocate II

Thank you for prompt response. That didn't work, throws an error on 'in'. the columnname is a char field.

Works for me 

kushanNa_1-1740710882262.png

 

maybe you are trying to use DAX code in M (Power Query) then it will throw an error on 'in' ? if that's the case then DAX functions cannot be used in M query 

 

Thaumaturgist
Helper I
Helper I

I'd recommend SWITCH. Give this a try:

SUMX(
tablename,
SWITCH(
TRUE(),
tablename[colname] IN {"a", "b"}, -1,
tablename[colname] IN {"c", "d"}, 0,
tablename[colname] IN {"e", "f"}, 1,
0
)
)

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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