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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

add dynamic row values from another table

Sorry if my post is duplicated. I had searched the issue and found nowhere. Let me know if i can do this way or not. If I can do then, can you please me on this.

 

I have 2 tables:
Table1- 
table1.1.JPG

Table2- 

table2.1.JPG

 
I want to create a new table using power query line below. Let me know if I can create by any other method also.
pm.JPG

 

The values in each row should be dynamically calculated for each row*column. Thanks in advance.

1 ACCEPTED SOLUTION

Hello @Anonymous 

 

change the AddedYear-step as follows

	AddedYear = Table.AddColumn
	(
		ChangeType,
		"Custom",
		each Date.Year
		(
		    [Date]
		)
	),


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

11 REPLIES 11
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

this involves quite a few transformation steps

First Combine both tables, then get a list of column names that have to be unpivoted (criteria was contains "quantity"). Apply an Unpivot of quantity-columns, add a new column with the year, delete all not needed columns finally pivot the table again.

Here the complete solutuion

let
	Table1 =
	let
		Source = #table 
		(
			{"Region","Territory","Date","Brand","Quantity1","Quantity2"},
			{ {"Central","A","Jan 2019","Nike","14","10"}, {"West","D","Feb 2019","Nike","5","54"} } 
		)
	 in 
		Source,
	Table2 =
		let
			Source = #table 
			(
				{"Region","Territory","Date","Brand","Quantity3"},
				{ {"Central","A","Sep 2020","Nike","12"}, {"North East","B","Feb 2019","Nike","11"} } 
			)
		 in 
			Source,
	Combine = Table.Combine
	(
		{Table1,Table2}
	),

	GetQuantityList = List.Select
	(
		Table.ColumnNames
		(
			Combine
		),
		each Text.Contains
		(
			Text.Lower
			(
				_
			),
			"quantity"
		)
	),
	Unpivot = Table.Unpivot 
	(
		Combine,
		GetQuantityList,
		"Quantity",
		"Value" 
	),
	ChangeType = Table.TransformColumnTypes
	(
		Unpivot,
		{{"Value", type number}}
	),
	AddedYear = Table.AddColumn
	(
		ChangeType,
		"Custom",
		each Date.Year
		(
			Date.FromText
			(
				[Date]
			)
		)
	),
	RemoveOtherColumns = Table.SelectColumns
	(
		AddedYear,
		{"Custom", "Value", "Quantity"}
	),
	PivotColumn = Table.Pivot
	(
		Table.TransformColumnTypes
		(
			RemoveOtherColumns,
			{{"Custom", type text}},
			"de-DE"
		),
		List.Distinct
		(
			Table.TransformColumnTypes
			(
				RemoveOtherColumns,
				{{"Custom", type text}},
				"de-DE"
			)
		[Custom]
		),
		"Custom",
		"Value",
		List.Sum
	)
 in 
	PivotColumn

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

Hi @Jimmy801 ,

I am trying to run the query and get the below error.
error.JPG

 

Hello @Anonymous 

 

change the AddedYear-step as follows

	AddedYear = Table.AddColumn
	(
		ChangeType,
		"Custom",
		each Date.Year
		(
		    [Date]
		)
	),


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

Hi @Jimmy801 ,

You are too good. If you dont mind, can you explain me from getQuantityList so that I can make few changes ? 
Please...

Hello @Anonymous 

 

thank you 😁

 

what kind a changes you want to make?

This function defines which columns are unpivoted in the next step. The List.Select Function does a filtering of all column names and in the current setting it searches for items where quantitiy is a part of the item.

So the definition happens exactly here

image.png

 

Hope it helps

 

Jimmy

 

Anonymous
Not applicable

Hi @Jimmy801 ,

I just have calculated column NetSales1 and NetSales2 as shown in below fig.
table1.1.JPG

I have calculated this using a lookup table
rate.JPGNetSales1 = Quantity1 * Rate1 

Using Power Query, I am not able to get the NetSales1 as a row as shown below. Please advise on this.
newPm.JPG

 

 

Hello @Anonymous 

 

just substitute the GetQuantityList with this code

	GetQuantityList = List.Select
	(
		Table.ColumnNames
		(
			Combine
		),
		each Text.Contains
		(
			Text.Lower
			(
				_
			),
			"quantity"
		) or 
        Text.Contains
		(
			Text.Lower
			(
				_
			),
			"netsales"
		)
	),

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

Anonymous
Not applicable

NetSales row is not shown in the table.  😕
latestqty.JPG

NetSales is a calculated column which is calculated by dax formula.

Hello @Anonymous 

 

if netsales is part of your data, then is there. If you are adding this information only on Power BI as additional DAX column, then there is no way to have it here in Power Query. Then you need to add this information as new column in Power Query instead

 

BR

 

Jimmy

Anonymous
Not applicable

Hey @Jimmy801 ,

Yes the netSales is calculated in power bi. Is there a way where i can calculate the column in power query.
Can you give me a ref link or example where i can calculate from lookup table and use conditions in it ?

Hello @Anonymous 

 

the general microsoft site is a good starting point link.

In your case check out the Table.NestedJoin-function. This function enables relationships between 2 tables. In case you have question, post a new question to the forum.

 

All the best

 

Jimmy

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.