Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi
I'm used to apply SUM.IF in Exel but I don't know how do the same via a Measure in Power BI.
I will illustrate my problem by an example. Let's say I have this data:
Sales opportunity, unique# | Sales prize | Revenue | Is the car blue? | Is the car a 4WD | Does the car have backseats? |
11 | 100 | 25 | True | False | True |
12 | 300 | 40 | False | False | False |
13 | 250 | 35 | False | False | False |
14 | 175 | 20 | False | True | False |
15 | 100 | 20 | False | False | False |
16 | 75 | 10 | True | False | True |
17 | 375 | 55 | True | True | True |
If I want to calculate and index that tells my what the average revenue is on all sales, I use this formula to create a Measure: Rev_average = (SUM (Data[Revenue]))/(COUNTROWS(Data)) * 100
My problem is that I also want to calculate revenue based on the entries where and only if one of the following values is true: “Is the car blue?”, “Is the car a 4WD”, ”Does the car have backseats?” So if all values is false it will not count in the average revenue.
Does anyone know how to do that?
BR
Anders
Solved! Go to Solution.
1. create the conditional filed which i mention in first reply on this post like this.
2. Create one calculation or Directly drag the Value measure into the card and choose as Average
3. Darg the final Condtional Column into visual filter and choose greater than "0" Thats it Dude.
Yes, @Baskar 's solution works fine for that purpose.
But if you're after a more robust solution, this measure would do:
NewAverage = CALCULATE(AVERAGE('Table2'[Revenue]), FILTER(Table2, 'Table2'[Include]=1))
No need to switch to Average in the report-design then.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi Anders,
Prob :
In your case we can't check string in IF statement in power BI.
so i suggest or my idea is
1. go to the Query Editor screen
2. Here u have to add three calculated column
like if "Is the car blue?" = "True" then 1 or 0
like for three condition
1
3. after creating the tree column add these three and create on ecolumn like : Column1 + Column2+Column 3
now save and close the editor window and move to canvas
they create a calculation like
Measure 2 = IF(SUM('Sample'[Custom])>0, SUM('Sample'[Revenue])/SUM('Sample'[Sales Prize]),0)
Output :
let me know if its not work!!!
As far as I can see, the measured average is not right. Why is that.
If do the same as you I get the numbers (with two decimals):
13,33+25+11,43+14,64 = 64,4 / 4 = 16,1 % (in average). The table show me 14,91 % which is wrong? Do I have to make a new measure to get a new average measure?
@Anonymous in that case create three measures as below,
AvgIfCarHasBackSeats = CALCULATE( (SUM(sam[Revenue]) / COUNt(sam[Revenue])) * 100 , sam[Does the car have backseats?] = "TRUE" )
AvgIfCarBlue = CALCULATE( (SUM(sam[Revenue]) / COUNt(sam[Revenue])) * 100 , sam[Is Car Blue?] = "TRUE" )
AvgIfCarIs4WD = Measure = CALCULATE( (SUM(sam[Revenue]) / COUNt(sam[Revenue])) * 100 , sam[Is the Car 4WD?] = "TRUE" )
@ankitpatira Thanks for your answer.
From your solution I will up evaluate each one of the values individual.
I want to evalualte the row including either one or more of each criteria to be TRUE.
BR
Anders
@Anonymous Below should work. also ensure column of true / false in power bi desktop are defined as data category Text.
Measure = CALCULATE( (SUM(sam[Revenue]) / COUNt(sam[Revenue])) * 100 ,
OR (
sam[Does the car have backseats?] = "TRUE",
sam[car 4wd?] = "TRUE",
sam[car blue?] = "TRUE"
))
@ankitpatira
I don't think the OR ( ) function for this works. Am I right?
It dosen't work for me... It says something about "the highest number of arguements for this function is 2" - do I put the seperators wrong?
@Anonymous ok then try with using SWITCH() function. SWITCH will work,
@ankitpatira
Can you please provide an example with the car table where you use the SWITCH() function?
In order to avoid dealing with multiple columns, you coud add a column in the query-editor which expresses in one column if the row is to be included or not.
If you have "real" TRUE or FALSE values in your columns, the expression would look like this:
List.AnyTrue( { ["Is the car blue?"], ["Is the car a 4WD"], ["Does the car have backseats?"] }) - this will return TRUE or FALSE
If they are text-values like this:
if List.Contains( { ["Is the car blue?"], ["Is the car a 4WD"], ["Does the car have backseats?"] }, "True") = true then "In" else "Out" - so you have to filter for "In" in your CALCULATE-statement.
The trick is to put all your column-values into a list - that way your expressions stay neat.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi
Aint' this the exact same as adding a column based on terms evaluating multiple columns at the same time?
Yes, the result is the same.
Should be an easy measure then.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Yeah it should. But I just cannot get the right average measure - do you know how?
If I understood your request right, it would probably be easiest if you return 0 for false and 1 true in the query. Then your measure would be this:
Average = IF(MIN('Table1'[Include])=0, 0, AVERAGE(Table2[Revenue]))
This measures effectively checks if there is any value with a false (0) in the current filter-context and then returns 0, otherwise it calculates the average Revenue of the current filter context.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Thats right.
Unfortunately when I do use this function, I don't get the average of the column.
Why is that?
Hi Anders,
Which u r getting the result is correct. bec it is row level average right ?
Try with any card . That will help you.
But am not sure the result is same which u did all in single Conditional column.
Can u please give me what excatly u want as a screen shot if possible. I will help you, and we will close your issue today !!!
All I want is this:
So if the value is true in one of the 3 columns it should take the average om the revenue from the none-zero values.
Hi Anders
That is you want right ?
1. create the conditional filed which i mention in first reply on this post like this.
2. Create one calculation or Directly drag the Value measure into the card and choose as Average
3. Darg the final Condtional Column into visual filter and choose greater than "0" Thats it Dude.
Yes, @Baskar 's solution works fine for that purpose.
But if you're after a more robust solution, this measure would do:
NewAverage = CALCULATE(AVERAGE('Table2'[Revenue]), FILTER(Table2, 'Table2'[Include]=1))
No need to switch to Average in the report-design then.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
71 | |
70 | |
38 | |
28 | |
26 |
User | Count |
---|---|
97 | |
88 | |
59 | |
43 | |
40 |