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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Extract value from a table and use it to remove rows in another table

Hello,

 

I have 2 tables.

 

Table 1 "Currently used Year" has a dynamic value. It only has one value, which is the year we're using in our database. This year is currently 2020, but it will change if the database is changed of course.

Table 1 looks like this:

Year

2020

 

Table 2 has 3 columns, including:

 

Category ||  Year  ||  Value 

Apple      ||  2002  ||   27401

Orange    || 2003   ||    3948

..................................................

Apple       || 2020  || 38401

Apple       || 2021  || 48090

Apple       || 2022  || 30101

Apple       || 2023  || 45000

...........................................

 

I want to

1) extract all the rows in table 2 with the year equal to or bigger than the year in table 1

2) each row that is has the year that is bigger or equal to the year in table 1, I want to get the value of that year / value of the year in table 1, grouped by Category

Example:

 

Apple  ||    2020   ||  10299  ||  10299/10299 = 1

Apple  ||    2021   ||   12000 ||  12000/10299 =  1,165

........

 

Thank you in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

Try Merge Function in Power Query Editor, then expand current value in Table2.

Here I will show you a sample.

Table2:

1.png

Table3:

2.png

Merge two tables by Category column in two tables:

3.png

Expand value column in Table3.

3.png

 

Best Regards,

Rico Zhou

 

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
amitchandak
Super User
Super User

@Anonymous , You can create one or measure like this and use

 

measure  =

var _max = maxx(allselected(Table1), Table1[Year])

return

calculate(sum(Table2[Value]), filter(Table2, Table2[Year] >=_max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hello,

 

Thank you for your answer. How can I do both 1) and 2) requests at once? And I hope to get this done in M (query editor)

Anonymous
Not applicable

Hi @Anonymous 

I think you can try to build a parameter and then filter Table2 by dynamic years you select in parameter and get result you want by M query. Here I will show you a sample.

Sample Table:

2.png

Build a Year Parameter as below steps.

1.png

Build two Custom column by M query.

Value for Select Years
=
let _Categroy = [Category]
in
     Table.SelectRows(#"Filtered Rows",each _Categroy =[Category] and [Year] = Year)[Value]{0}
Result
=
[Value]/[Value for Select Years]

Result is as below.

3.png

Best Regards,

Rico Zhou

 

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 Rico,

 

Unfortunately I cannot use the parameter because the current year number will be changed, it is a dynamic number. Is there any other way I can do this?

 

P-

Anonymous
Not applicable

Hi @Anonymous 

Parameter List is a good way for you to change years and get different result from it in Table 2.

You can see more details in Power Query Editor in my sample.

Select 2020 in Year Parameter.

1.png

Result:

2.png

Select 2019 in Year Parameter.

2.png

Result:

3.png

Parameter list can be changed, it is dyanmic.

 

Best Regards,

Rico Zhou

 

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 Rico,

 

Thank you for your reply. Currently I am aiming at so I do not have to do anything like changing the Parameters or adding years into the list, as in your solution.

 

However I have made another table (Table 3) with the Category and Value of only current year by appending the Table 1 with table 2 and did some filtering.

 

Table 3 is like this:

 

Category ||  Value  ||  Year

Orange    ||  2849   || 2020

Apple       || 8911    || 2020

Grape       || 1891    || 2020

 

I figure if I can input this table with table 2 based on the Category then I will get very close.

 

Desired table 2:

 

Category      ||       Year      ||       Value      ||     Value of current year (in this case 2020)

Apple            ||     2021      ||         7941      ||   3499

....

 

How can I do this with M? I have tried:

Table.AddColumn(each #"Table3"[Value] if [Category] = "Table3"[Category])

 

But it does not work. Do you have any suggestion how to fix this?

 

Anonymous
Not applicable

Hi @Anonymous 

Try Merge Function in Power Query Editor, then expand current value in Table2.

Here I will show you a sample.

Table2:

1.png

Table3:

2.png

Merge two tables by Category column in two tables:

3.png

Expand value column in Table3.

3.png

 

Best Regards,

Rico Zhou

 

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,

 

Thank you. I have merged and it worked!

 

Cheers,

 

P-

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.