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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

New column with max values from table 2 based on conditions in columns in table 1 dinamically

Hi everyone,
I am a recent user (I am not a programmer) of Power Query with Excel as a tool for data manipulation. Now I am stuck with a step which has taken my several days of google searching with no success. As a result of that search I found you in the Power BI community and I believe you may help me based on your successful background in the community. Please let me introduce you my case:
I have two query tables, table1 has several fields a shown in figure 1. I am trying to add a new column whose values depend of the other columns dynamically. Each cell in this column is the max value in other table’s column, named “Value”. For that purpose, I first filter Table2, based on four conditions. Then I get the max value by using List.Max (See formula below). For filtering table2 I have used static values, however, I’d wish to use values contained in each row of table1’s columns. It can be said that Table 1 is a subset of Table 2, where I managed to create a StartDate Column to get a data range. Then a Max value between two dates from Table 2's column “Value” can be obtained. 

Table 1

(Condition 1)

(Condition 2)

(Condition 3)

(Condition 4)

Result

Column1

Column2

StartDate

EndDate

MaxMinValue

Data1

A

19/03/2020

19/03/2020

3.4195

Data1

B

20/03/2020

09/04/2020

3.4195

Data1

B

16/01/2020

20/03/2020

3.4195

Data1

C

21/11/2019

16/01/2020

3.4195

Data1

C

18/11/2019

21/11/2019

3.4195

Data1

C

15/10/2019

18/11/2019

3.4195

Data2

D

08/03/2019

15/10/2019

3.4195

 

Formula to add a new column:

 

Table.AddColumn(Source, "MaxMinValue", each List.Max(Table.SelectRows(Table2, each [Column1]="Data1" and [Column2] = "A" and [Date] > #date(2020,2,26) and [Date] <= #date(2020, 4,9))[Close]))

 

Table 2

Column1

Column2

Date

Value

Data1

A

09/04/2020

20

Data1

A

08/04/2020

19.695

Data1

A

07/04/2020

19.845

Data1

B

06/04/2020

18.17

Data1

B

03/04/2020

16.9

Data1

C

02/04/2020

17.195

Data1

C

01/04/2020

16.985

Data2

D

31/03/2020

17.815

Data2

D

30/03/2020

16.29


I would appreciate your valuable help since all my tries have failed. Thank you in advance.
Regards
Julian, @Stachu , @ImkeF , @Greg_Deckler 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Check steps below:

Capture4.JPGCapture5.JPGCapture7.JPGCapture9.JPGCapture10.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Check steps below:

Capture4.JPGCapture5.JPGCapture7.JPGCapture9.JPGCapture10.JPG

 

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

Anonymous
Not applicable

Thank you @v-juanli-msft very much for your valuable help.

 

Regards

Stachu
Community Champion
Community Champion

Can you add sample tables (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1 Column2
A 1
B 2.5

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Sure. There it goes. Thank you

ImkeF
Community Champion
Community Champion

Hi @Anonymous 

reading through your request, that sounds like a circular dependency, but maybe I'm wrong.

Please provide a spreadsheet sample with the desired logic. Especially providing the values of the desired new column in Table1.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi. I found a solution.

Thank you for your interest in replying my request.

 

Julian

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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