cancel
Showing results for
Did you mean:
Regular Visitor

## Create a Calculated Column based on IF() conditions

I am fairly new to Power Bi and have searched in various online help forums but was unsuccessful in finding the one similar to mine. Hence posting this here. Not sure if this is a fairly straightforward one or complicated (as I think!)

I have 3 columns: 'Event', 'Screen' and 'Time' (Similar to below)

I want do a single calculation as below:

(2*count of "NameSubmitted" occurrences in Event) - (AVG Time of corresponding "NameSubmitted" (from Event) * count of "NameSubmitted" occurrences in Event)

+

+

(2*count of "OrderCreated" occurrences in Event) - (AVG Time of corresponding sum of "Orders"+"OrderDetail"+"OrderConfirmation" (from screen) * count of "OrderCreated" occurrences in Event)

My approach:

I have tried to create a new column with the following "IF()" function calculation but in vain (Started like below) and been receiving the following error:

```Calc =
CALCULATE(
(2*SUM(IF(Table[Event] = "NameSubmitted",1,BLANK())))
- AVERAGE(IF(Table[Event] = "NameSubmitted")
))  .....```

Error: The SUM function only accepts a column reference as an argument.

So, what would be a best way to achieve this calculation?

Any help is much appreciated.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

## Re: Create a Calculated Column based on IF() conditions

Would this calculated column be a good place to start?  If it produces the value you need, it should be easy to extend to incorporate the other event types

```Column =
VAR CountOfNameSubmitted = CALCULATE(COUNTROWS('Table'),ALL('Table'),'Table'[Event]="NameSubmitted")
VAR AverageOfNameSubmitted = CALCULATE(AVERAGE('Table'[Time]),ALL('Table'),'Table'[Event]="NameSubmitted")
RETURN (2*CountOfNameSubmitted) - (AverageOfNameSubmitted * CountOfNameSubmitted)```

Proud to be a Datanaut!

Super Contributor

## Re: Create a Calculated Column based on IF() conditions

Would this calculated column be a good place to start?  If it produces the value you need, it should be easy to extend to incorporate the other event types

```Column =
VAR CountOfNameSubmitted = CALCULATE(COUNTROWS('Table'),ALL('Table'),'Table'[Event]="NameSubmitted")
VAR AverageOfNameSubmitted = CALCULATE(AVERAGE('Table'[Time]),ALL('Table'),'Table'[Event]="NameSubmitted")
RETURN (2*CountOfNameSubmitted) - (AverageOfNameSubmitted * CountOfNameSubmitted)```