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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors