Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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.
Solved! Go to Solution.
Works for me
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
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.
Hi @rnola16 ,
If the problem has been solved, please accept as solution the replies you find helpful.
Best regards,
Mengmeng Li
Thank you for prompt response. That didn't work, throws an error on 'in'. the columnname is a char field.
Works for me
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
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
)
)
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
80 | |
59 | |
35 | |
35 |
User | Count |
---|---|
100 | |
62 | |
56 | |
47 | |
41 |