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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jgiolli
Regular Visitor

Conditional Column using IF statement comparing two different columns in two tables

I am trying to compare two columns which include revenue from two different tables.  Column 1 is project amount and it would contain revenue for projects from our CRM tables.  Column 2 is revenue from our ERP system tables.  What I'd like to do is look at Column 2 and for any values that are 0, I'd like to replace that with what is in column 1 in the CRM table.

 

I tried doing this in measures but the subtotals would not work properly so believe I need a custom column or conditional column.  This is the formula I used for the measure.  Any help would be greatly appreciated.

 

IF(sum(PA01201[PARetainer_Fee_Amount])= 0, sum(New_Project[New_revenue]), sum(PA01201[PARetainer_Fee_Amount]))
7 REPLIES 7
DataInsights
Super User
Super User

@jgiolli,

 

Try this calculated column in the ERP table PA01201. It performs a lookup using Date.

 

New_revenue = 
VAR vAmountERP = PA01201[PARetainer_Fee_Amount]
VAR vAmountCRM =
    LOOKUPVALUE ( New_Project[New_revenue], New_Project[Date], PA01201[Date] )
VAR vResult =
    IF ( vAmountERP = 0, vAmountCRM, vAmountERP )
RETURN
    vResult

 

CRM table New_Project:

 

DataInsights_0-1634824696824.png

 

ERP table PA01201:

 

DataInsights_1-1634824714276.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Its saying that LOOKUPVALUE is not a function and as a result its not letting me lookup a field. Also, instead of date we want to compare based on New_Project[Project_Number].  

@jgiolli,

 

Are you creating a calculated column? LOOKUPVALUE should be available.

 

To lookup on a different column, simply replace Date with Project_Number:

 

LOOKUPVALUE ( New_Project[New_revenue], New_Project[Project_Number], PA01201[Project_Number] )

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I'm going into the field list under the table PA1201, selecting new column and adding the formula you provided.  Its saying LOOKUPVALUE is not a function.  Not sure if there is another place I should be doing creating this column.

Could it be because I am in direct query mode?

So good news is that this error was occuring because of the direct query which is now fixed.  However, now I'm getting a different error.  Here's the expression as entered:

 

New_revenue = VAR vAmountERP = PA01201[PARetainer_Fee_Amount] VAR vAmountCRM = LOOKUPVALUE ( New_Project[New_revenue], New_Project[Project Number], PA01201[PAcontid] ) VAR vResult = IF ( vAmountERP = 0, vAmountCRM, vAmountERP ) RETURN vResult
 
The error says a table of multiple values was supplied where a single value was expected.  Any ideas on how to resolve?  Thanks for your help!

@jgiolli,

 

Verify that you have one row per project.

 

https://dax.guide/lookupvalue/ 

 

"If multiple rows match the search values and in all cases Result_Column values are identical then that value is returned. However, if Result_Column returns different values an error is returned."





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.