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
Namoh
Post Partisan
Post Partisan

Formula with data from two not directly connected tables

Hi.

 

I have a bunch of tables, connected as follows.

Table FM connected to table ID

Table kpi connected to ID

Table Targets connected to FM

 

I've got another table kpi2 which is a copy of kpi

 

I want to add a column to kpi2 with the following requierments:

- if column A from table kpi2 = column B from table Targets AND column C from table kpi2 = column D from table targets then column E from Targets otherwise null

 

Is this possible?

1 ACCEPTED SOLUTION

HI @Namoh 

You could use this formula to add a custom column in power query

 

 

List.Sum(Table.SelectRows(Target, 
(Target) =>  ( Target[Column B]= [Column A])
and (Target[Column D]=[Column C])

)[Column E])

 

Result:

2.JPG

 

https://docs.microsoft.com/en-us/powerquery-m/table-selectrows

https://docs.microsoft.com/en-us/powerquery-m/list-sum

 

and for your case, I also suggest you use merge to get it

3.JPG

then expand it:

4.JPG

https://radacad.com/append-vs-merge-in-power-bi-and-power-query

 

here is sample pbix file, please try it.

 

Regards,

Lin

Community Support Team _ Lin
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

7 REPLIES 7
amitchandak
Super User
Super User

@Namoh ,Can you share sample data and sample output in table format?

Basically table kpi2 has data from multiple years and multiple months for multiple units.

Table Targets has only data for some years and months.

I need to add that data as a column for the related years/months/units.

Table KPI2

Column AColumn C
123apr-20
213apr-20
325apr-20
623may-20
123may-20
213may-20
432may-20

 

Column BColumn DColumn E
213apr-2080
325apr-2054
100apr-2023
123may-2065
213may-2025
420may-2090

KPI2 wanted

Column AColumn CNew Column 
123apr-20null
213apr-2080
325apr-2054
623may-20null
123may-2065
213may-2025
432may-20null

 

Hope this explains what I want.
And hope this is what you wanted to see.

@Namoh , Try new column in KPI2 table

sumx(filter(Target, Target[Column B] = KPI2[Column A] && Target[Column D] = KPI2[Column C]),Target[Column E])

Thanks for your reply, but I don't get it to work.

 

I think this is a DAX query, while I'm in PQE.

 

What would be the PQE formula?

HI @Namoh 

You could use this formula to add a custom column in power query

 

 

List.Sum(Table.SelectRows(Target, 
(Target) =>  ( Target[Column B]= [Column A])
and (Target[Column D]=[Column C])

)[Column E])

 

Result:

2.JPG

 

https://docs.microsoft.com/en-us/powerquery-m/table-selectrows

https://docs.microsoft.com/en-us/powerquery-m/list-sum

 

and for your case, I also suggest you use merge to get it

3.JPG

then expand it:

4.JPG

https://radacad.com/append-vs-merge-in-power-bi-and-power-query

 

here is sample pbix file, please try it.

 

Regards,

Lin

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

Merge, of course!!

 

Why do I always want to make it difficult with formulas..??

 

This worked perfectly.

 

Thanks.

Is what I want not possible in PQE or am I doing something wrong?

If more information is needed, please let me know.

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.