Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
My data looks like
Id | Category | Sensi1 | Sensi2 |
1 | A | 100 | -50 |
2 | B | 200 | -60 |
3 | A | 300 | -70 |
4 | B | 400 | -80 |
5 | B | 500 | -90 |
I want to implement that is Category = A then return Sensi1 + Sensi2 else return Sensi1. How would I do that?
Solved! Go to Solution.
Hi @alsm ,
try
Conditional Sum =
SUMX (
VALUES ( 'Table'[Category] ),
CALCULATE (
SUM ( 'Table'[Sensi1] )
) +
IF (
'Table'[Category] = "A",
CALCULATE (
SUM ( 'Table'[Sensi2] )
)
)
)
@Martin_D , thank you. It works.. though the first part
VALUES ( 'Table'[Category] )
is non-intuitive . Its basically saying evaluate every line on the dashboard. Is it correct?
I tried and created another variant
total_sensi =
VAR sensi1 =
CALCULATE ( SUM ( Table[Sensi1] ) )
VAR sensi2 =
CALCULATE ( SUM ( Table[Sens2] ), FILTER ( Table, Table[Sensi2] = "A" ) )
VAR total_sensi = sensi1 + sensi2
RETURN
total_sensi
Answers are same in both cases, is there a way to say one solution is more optimal than other?
I was not 100% sure whether you want to use it as a measure or calculated column, so I wrote code that works for both. Actually, the same should be true for your solution. In a visual that shows values by Category both solution should perform about the same. With a large number of categories yours might be even faster in the grand total.
Thank you for your reply and showing me another way to do it....
FYI: I created a measure (not a column)
Hi @alsm ,
try
Conditional Sum =
SUMX (
VALUES ( 'Table'[Category] ),
CALCULATE (
SUM ( 'Table'[Sensi1] )
) +
IF (
'Table'[Category] = "A",
CALCULATE (
SUM ( 'Table'[Sensi2] )
)
)
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
17 | |
10 | |
10 | |
8 | |
6 |
User | Count |
---|---|
20 | |
18 | |
16 | |
13 | |
10 |