cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MissMintox Regular Visitor
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)

 Capture.PNG

 

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
Phil_Seamark Super Contributor
Super Contributor

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

HI @MissMintox

 

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)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

1 REPLY 1
Phil_Seamark Super Contributor
Super Contributor

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

HI @MissMintox

 

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)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!