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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

using index columns to combine data from two tables

I need to combine data from two tables.

Table A looks like this where Index Start and Index Stop map to Index in Table B.

Table.png

 Table B looks like this. The Index column lists only the values that span from Index Start to Index Stop for the records in Table A. The last index number is 62.

first image.png

I want to combine these data to look like this.

result.png

The total record count in this example would be 52.

record count.png

 

This is all in an effort to use PBI to read a structured report of user configurations (xlsx) and re-organize the data.

The data source looks like this.

PBIuseNpa_2-1660324210436.png

 

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

Hi @Anonymous ,

 

I think you can add a custom column in Table A by this code in Power Query Editor.

Index =

{Number.From([Index Start])
..
if 
[Index End] = null 
then
List.Max(#"Table B"[Index]) 
else 
Number.From([Index End])}

RicoZhou_1-1660719199092.png

 

Then expand Index in Table A.

RicoZhou_2-1660719242234.png

And then merge Table A and Table B by Index columns.

For reference: merge-queries-overview

RicoZhou_3-1660719351777.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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

I think you can add a custom column in Table A by this code in Power Query Editor.

Index =

{Number.From([Index Start])
..
if 
[Index End] = null 
then
List.Max(#"Table B"[Index]) 
else 
Number.From([Index End])}

RicoZhou_1-1660719199092.png

 

Then expand Index in Table A.

RicoZhou_2-1660719242234.png

And then merge Table A and Table B by Index columns.

For reference: merge-queries-overview

RicoZhou_3-1660719351777.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.

 

 

KratosBI
Regular Visitor

You will need to pivot table A to then join to table B, so the results look like this:

 

User_ID, Index

4383961,3

4383961,4

4383961,5

4383961,6

4383961,7

4383961,8

4383961,9

 

I have seen this done in Power Query, but my Google-Foo failed me for an example.

 

Your biggest challenge will be getting the right # of records to fill in for table A. 

 

After you get the right num of columns, go to 'column by example' to figure it out how to fill in the missing values for the index. 

Power BI- Column From Example. In this article, we learn about the… | by Vaishali Goilkar | Medium

 

I hope this helps. Good luck.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.