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 August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Calculating an index from true/false data - SUM.IF formula

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 prizeRevenueIs the car blue?Is the car a 4WDDoes the car have backseats?
1110025TrueFalseTrue
1230040FalseFalseFalse
1325035FalseFalseFalse
1417520FalseTrueFalse
1510020FalseFalseFalse
167510TrueFalseTrue
1737555TrueTrueTrue

 

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

2 ACCEPTED SOLUTIONS

1. create the conditional filed which i mention in first reply on this post like this.

1.JPG

 

 

2. Create one calculation or Directly drag the Value measure into the card and choose as Average 

 3.JPG

 

3. Darg the final Condtional Column into visual filter  and choose greater than "0" Thats it Dude.

 2.JPG

 

View solution in original post

ImkeF
Community Champion
Community Champion

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

View solution in original post

24 REPLIES 24
Baskar
Resident Rockstar
Resident Rockstar

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

 

11

3. after creating the tree column add these three and create on ecolumn like : Column1 + Column2+Column 3

 

 

2.JPG

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 :

 

3.JPG

 

let me know if its not work!!!

 

 

Anonymous
Not applicable

@Baskar

 

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?

 

 

ankitpatira
Community Champion
Community Champion

@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" )

Anonymous
Not applicable

@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"

))

 

 

Anonymous
Not applicable

@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,

Anonymous
Not applicable

@ankitpatira
Can you please provide an example with the car table where you use the SWITCH() function?

ImkeF
Community Champion
Community Champion

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

Anonymous
Not applicable

@ImkeF

 

Hi

 

Aint' this the exact same as adding a column based on terms evaluating multiple columns at the same time?

1.JPG

 

 

 

 

ImkeF
Community Champion
Community Champion

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

Anonymous
Not applicable

@ImkeF

Yeah it should. But I just cannot get the right average measure - do you know how?

ImkeF
Community Champion
Community Champion

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

Anonymous
Not applicable

@ImkeF

 

Thats right.

 

Unfortunately when I do use this function, I don't get the average of the column.

1.JPG

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 !!!

Anonymous
Not applicable

@Baskar

 

All I want is this:

11.JPG 

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

 

1.JPG

 That is you want right ?

 

Anonymous
Not applicable

@Baskar

 

Yes thats right.

1. create the conditional filed which i mention in first reply on this post like this.

1.JPG

 

 

2. Create one calculation or Directly drag the Value measure into the card and choose as Average 

 3.JPG

 

3. Darg the final Condtional Column into visual filter  and choose greater than "0" Thats it Dude.

 2.JPG

 

ImkeF
Community Champion
Community Champion

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.