Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MissMintox
Helper I
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)

 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
Phil_Seamark
Employee
Employee

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!

View solution in original post

1 REPLY 1
Phil_Seamark
Employee
Employee

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!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors