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
shenliwei1019
New Member

Loop table to add column and values ​​from another table

I am a new user of power query, please forgive me for the following questions:

Example 1:

I have a table A(According field Number of vehicles descending).The table is not sorted initially.

| Car ID | Number of vehicles |
| ------ | ------------------ |
| ED2399 | 3 |
| AUN203 | 2 |
| EJ3263 | 1 |
| EG0209 | 1 |
 I have a table B(Group Column value = Group({"Model", "Tax ID"}, RowCount), According field Group descending).The table is not grouped and sorted initially.

| Model | Tax ID | Price | Group |
| ------------- | ---------- | ----- | ----- |
| Panamera A311 | 8703236110 | 2130 | 4 |
| Panamera A311 | 8703236110 | 2130 | 4 |
| Panamera A311 | 8703236110 | 2085 | 4 |
| Panamera A311 | 8703236110 | 2170 | 4 |
| Macan A171 | 8703236310 | 1660 | 2 |
| Macan A171 | 8703236310 | 1660 | 2 |
| Cayenne A361 | 8703234310 | 2140 | 1 |
Table A sum(Number of vehicles) = Table B total Row Count. Field Number of vehicles value Match Field Group value.

Desired Outcome:

| Model | Tax ID | Price | Group | Car ID |
| ------------- | ---------- | ----- | ----- | ------ |
| Panamera A311 | 8703236110 | 2130 | 4 | ED2399 |
| Panamera A311 | 8703236110 | 2130 | 4 | ED2399 |
| Panamera A311 | 8703236110 | 2085 | 4 | ED2399 |
| Panamera A311 | 8703236110 | 2170 | 4 | EJ3263 |
| Macan A171 | 8703236310 | 1660 | 2 | AUN203 |
| Macan A171 | 8703236310 | 1660 | 2 | AUN203 |
| Cayenne A361 | 8703234310 | 2140 | 1 | EG0209 |
Example 2:

I have a table A(According field Number of vehicles descending).The table is not sorted initially.

| Car ID | Number of vehicles |
| ------ | ------------------ |
| ED2399 | 4 |
| AUN203 | 3 |
I have a table B(Group Column value = Group({"Model", "Tax ID"}, RowCount), According field Group descending).The table is not grouped and sorted initially.

| Model | Tax ID | Price | Group |
| ------------- | ---------- | ----- | ----- |
| Panamera A311 | 8703236110 | 2130 | 2 |
| Panamera A311 | 8703236110 | 2130 | 2 |
| Macan A171 | 8703236310 | 1660 | 2 |
| Macan A171 | 8703236310 | 1660 | 2 |
| Panamera A312 | 8703234310 | 2140 | 1 |
| Boxster A422 | 8703234110 | 2085 | 1 |
| Cayenne A361 | 8703236310 | 2140 | 1 |
Table A sum(Number of vehicles) = Table B total Row Count. Field Number of vehicles value Match Field Group value.

Desired Outcome:

| Model | Tax ID | Price | Group | Car ID |
| ------------- | ---------- | ----- | ----- | ------ |
| Panamera A311 | 8703236110 | 2130 | 2 | ED2399 |
| Panamera A311 | 8703236110 | 2130 | 2 | ED2399 |
| Macan A171 | 8703236310 | 1660 | 2 | ED2399 |
| Macan A171 | 8703236310 | 1660 | 2 | ED2399 |
| Panamera A312 | 8703234310 | 2140 | 1 | AUN203 |
| Boxster A422 | 8703234110 | 2085 | 1 | AUN203 |
| Cayenne A361 | 8703236310 | 2140 | 1 | AUN203 |
Please help me, thanks!

2 REPLIES 2
Omid_Motamedise
Super User
Super User

for the loop in power query, check this video

 

https://youtu.be/G8PRbWuDcmQ?si=jQJ0UCuCf3PUjtXq

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
lbendlin
Super User
Super User

For your example 1 what is the allocation logic? Does a Car ID have to fit completely into a group?

 

Example 2 seems to ignore the last two cars. Not clear what the allocation logic should be.

 

Note:  Power BI is not a resource planning tool.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors