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
Anonymous
Not applicable

Help with M code + Vlookup

Hello!

 

I am creating a complex database that will have import info from Share point list and connect to Data Lake databases.

 

I have no experience/knowledge with  M code but I would like to use it instead of DAX because its possible to filter the rows in the query mode that will improve a lot the speed/size of this power bi file since I will use a lot of large databases.

 

I will make also easier when I will use the same table mirror for this table for other filtering conditions for the same table.

 

Table A

ECODICE MECO
686638596517
686638596517
686638612180
686638621342

 

Table B

 

FA Proj. IDProj. ref. typeProj. ref. DICE MECO(s) / ECO(s)
22DICE MECO596517
23DICE MECO643711
24DICE MECO660949
25DICE MECO685692
26DICE MECO695569
27DICE MECO704182
28ECO686638
30DICE MECO668426
31DICE MECO612180
31DICE MECO621342
33DICE MECO685694

 

I would like to add the column "FA Proj. ID" in the table A based on the values for column B with 2 variants, when is ECO in the Proj. ref. type should look in the 1st column in the table A  or when its DICE MECO in the Proj. ref. type for the 2nd column for the table A when is a match with the values for the column DICE MECO(s) / ECO(s) from the table B.

 

I tried to search similar cases but I didn´t find it.

 

Hope that I can get help with that!

 

Best regards,

 

André Fortunato

 

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

Sorry for the late reply because of the weekend. You can try the custom column in PQ. Sample file is below.

Like this:

let 
t1=Table.SelectRows(#"TableB",(x)=>x[DICE_MECO ECO]=[ECO]),
t2= Table.SelectRows(#"TableB",(x)=>x[DICE_MECO ECO]=[DICE MECO]) 
in 
if Table.RowCount(t1)>0
then List.Sum(t1[FA Proj. ID])
else if Table.RowCount(t2)>0
then List.Sum(t2[FA Proj. ID])
else null

vjaneygmsft_0-1626083137015.png

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

In this case, do you want 22 or 28? Can you show me the desired result? 

vjaneygmsft_0-1625801123646.png

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello @v-janeyg-msft !

 

Thanks a lot for your reply and support!

 

My apologies for that, I added wrong values in the ECO column. See below the desired result:

Andr_Fortunato_0-1625807007510.png

 

Best regards,

André Fortunato

Hi, @Anonymous 

 

Sorry for the late reply because of the weekend. You can try the custom column in PQ. Sample file is below.

Like this:

let 
t1=Table.SelectRows(#"TableB",(x)=>x[DICE_MECO ECO]=[ECO]),
t2= Table.SelectRows(#"TableB",(x)=>x[DICE_MECO ECO]=[DICE MECO]) 
in 
if Table.RowCount(t1)>0
then List.Sum(t1[FA Proj. ID])
else if Table.RowCount(t2)>0
then List.Sum(t2[FA Proj. ID])
else null

vjaneygmsft_0-1626083137015.png

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @v-janeyg-msft !

I tested the code and works great.

I just have a new issue that takes much more time to load the table A from a OBDC data source but I can load this table by a routine.

Many thanks once again and have a great weekend,

Regards, André

Anonymous
Not applicable

Hi @v-janeyg-msft ,

 

No worries, I am in summer holidays from last Monday but I will be able to test the proposed solution only in the middle/end of the next week.


Thanks a lot once again for your help!

 

Best regards, André

Hi, @Anonymous 

 

I need a complete logic, If the two columns of a row in table A can match the id in table B, how to deal with it, is there such a situation? Please explain.

 

Best Regards

Janey Guo

Anonymous
Not applicable

Hi @v-janeyg-msft !


The filter ut will be always the table B, if column Proj. type ref. is a ECO they should vlookup the value from the DICE MECO(s) / ECO(s) in the column ECO from table A and add a new column with the FA. Proj. iD in the table A from the table B, the same logic if the value from the column Proj. type ref. From table B is a DICE MECO but should vlookup the values from the table A from the column DICE MECO instead.

it will be always distinct values for ECO or MECO in the table A or B but I am only interested to retrieve in the table A the DICE MECO / ECOs from table B and tag the Proj ID in the table A.

 

Please let me know if you need more input 🙂

 

Best regards,

 

André Fortunato 

@Anonymous  I understand and I will reply to you later.

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