cancel
Showing results for
Did you mean:
Highlighted
Helper I

## 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 "AddressAdded" occurrences in Event) - (AVG Time of corresponding "AddAddress" (from screen) * count of "AddressAdded" 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
Microsoft

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

Microsoft

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

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors