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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
VHosamane
Frequent Visitor

Match multiple columns and find corresponding values using DAX

Here is the scenario that I have and need help with DAX calculated field syntax to arrive with the two fields in the Transaction-Table.

 

I have a lookup table as shown, which has distinct rows with combination of ClientName and ProjectName.

LookUp-Table

ClientNameProjectNameProjectTypeProduct
Client1Project1TechSAAS
Client2Project2ServiceIT
Client1Project2TechR&D
Client2Project1ServiceIT
Client3Project3BothSAAS
Client3Project1ServiceR&D

 

 

Transaction-Table

Client

Name

Project

Name

Project

Cost

Emp

Name

LookUp

EmpType

Timesheet

Date

Input

Hr

LookUp

EmpRate

Calc

EmpCost

Calc

Product

Calc

ProjectType

Client1Project1$9,999,999EmpAEmp2-Jan4$100$400SAASTech
Client1Project1$9,999,999EmpBContract2-Jan4$200$800SAASTech
Client1Project1$9,999,999EmpCEmp2-Jan4$100$400SAASTech
Client1Project1$9,999,999EmpDEmp2-Jan4$100$400SAASTech
Client1Project2$1,000,000EmpAEmp9-Feb8$100$800R&DTech
Client1Project2$1,000,000EmpBContract9-Feb8$200$1,200R&DTech
Client2Project1$5,000,000EmpMEmp2-Jan8$100$800ITService
Client2Project1$5,000,000EmpMEmp12-Jan8$100$800ITService
Client4Project1$7,500,000Emp AEmp10-Apr8$100$800N/AN/A
Client1Project7$100,000EmpAEmp2-Feb8$100$800N/A

N/A

          

 

 

Based on ClientName and Project name in Transaction-Table, need to look up ProjectType & Product in the Look-Up table and get the value into the Transaction-Table, Calc-Product & Calc-ProjectType respectively. If the combination of ClientName and ProjectName does not exist, then enter N/A in both the columns.

 

Can you please help with the DAX calculated field syntax in the Transaction-Table? Would it be possible without joining/ linking the two tables?

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Use Power Query, Merge the queries on ClientName and ProjectName using a LEFT join (with the transaction table first).

Expand the 'Table' column to return Product and Project Type.

Replace any null value with N/A

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Yes, it is possible but I'd do it in Power Query as suggested by @HotChilli. If your transaction table is really big, then creating calculated columns like this is a NO-NO.

 

But one of the columns would be (I don't recommend doing it this way, TT - transaction table, LT - lookup table):

Calc-Product =
var __client = TT[Client Name]
var __proj = TT[Project Name]
var __product = 
	CALCULATE(
		VALUES( LT[Product] ),
		TREATAS(
			{__client, __proj},
			LT[Client Name],
			LT[Project Name]
		),
	)
return
	if( __product = blank(), "N/A", __product )

If this expression errors out somewhere, it means that VALUES( LT[Product] ) returns more than 1 value and you have a problem with duplication in the LT. Bear in mind that this will work OK when there are NO RELATIONSHIPS between the two tables. If there are, then you should use the RELATED function.

 

Best

Darek

What's wrong in the calculated formula syntax?

Anonymous
Not applicable

Remove the comma from before the parenthesis that ends CALCULATE.

 

Best

Darek

Thank you @Anonymous & @HotChilli . I tried both solutions and went with solution mentiond by @HotChilli. As @Anonymous  rightly mentioned in the note that the solution would work only if there is no relationship. So it's very important to go through the details. Thank you very much to both of you. 

Hi Darek,

 

Calc-Product = 
var __client = TT[Client_Name]
var __proj = TT[Project_Name]
var __product =
    CALCULATE(
            VALUES(LT[Product]),
            TREATAS(
                {__client, __proj},
                LT[ClientName],
                LT[ProjectName]
                ),
            )
return
    IF(__product = BLANK(), "N/A", __product)
I tried this code, but gets this error: Argument '3' in CALCULATE function is required.
HotChilli
Super User
Super User

Use Power Query, Merge the queries on ClientName and ProjectName using a LEFT join (with the transaction table first).

Expand the 'Table' column to return Product and Project Type.

Replace any null value with N/A

calerof
Impactful Individual
Impactful Individual

Hi @HotChilli ,

Thank you very much for this response, I was not aware that it was possible to do nested joints, i.e. merge two tables with more than one key columns. 

Great,

happy learning!

Fernando

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.