Forum Discussion
MT_1909
Oct 30, 2023Copper Contributor
Data transformation using Power Query?
Hi Everyone,
I have a worksheet with 50k+ rows and would like to create a lineage using power query but I can't seem to get it right.
Can someone please help? Thank you so much in advance!
Here's a sample of my data:
Source DB | Source Table | Source Column | Target DB | Target Table | Target Column |
S_DB1 | S_Table1 | S_Column1 | T_DB1 | T_Table1 | T_Column1 |
T_DB1 | T_Table1 | T_Column1 | T_DB2 | T_Table2 | T_Column2 |
T_DB2 | T_Table2 | T_Column2 | T_DB4 | T_Table4 | T_Column4 |
T_DB4 | T_Table4 | T_Column4 | T_DB6 | T_Table6 | T_Column6 |
S_DB3 | S_Table3 | S_Column3 | T_DB3 | T_Table3 | T_Column3 |
T_DB3 | T_Table3 | T_Column3 | T_DB7 | T_Table7 | T_Column7 |
T_DB7 | T_Table7 | T_Column7 | T_DB9 | T_Table9 | T_Column9 |
My desired outcome is ...
Source DB | Source Table | Source Column | Target DB | Target Table | Target Column | Target DB Hop 1 | Target Table Hop 1 | Target Column Hop 1 | Target DB Hop 2 | Target Table Hop 2 | Target Column Hop 2 | Target DB Hop 3 | Target Table Hop 3 | Target Column Hop 3 |
S_DB1 | S_Table1 | S_Column1 | T_DB1 | T_Table1 | T_Column1 | T_DB2 | T_Table2 | T_Column2 | T_DB4 | T_Table4 | T_Column4 | T_DB6 | T_Table6 | T_Column6 |
S_DB3 | S_Table3 | S_Column3 | T_DB3 | T_Table3 | T_Column3 | T_DB7 | T_Table7 | T_Column7 | T_DB9 | T_Table9 | T_Column9 |
- LorenzoSilver Contributor
Hi MT_1909
Check the attached Power Query. It seems to do it although there's something I really don't understand in what you expect vs. your source data. So, if that query doesn't do it you will have to explain the logic to apply
Note that I kept a blank row between each record as you seem to expect - easy to remove of course...
- MT_1909Copper Contributor
Hi Lorenzo
I used the code in your file but am getting an expression error: "There weren't enough elements in the enumeration to complete the operation."
Details:
[List]
The only change I made was the Source = myFilename (instead of SourceTable) in the Linage table.
The blank rows are not needed, I just added for ease of reading the data.
My goal is to see the data in 1 row/multiple columns for each Source Column, instead of multiple rows.
Can you please let me know what changes are needed to get your code to work?
Thanks again!
- LorenzoSilver Contributor
Hi MT_1909
What changes are needed to get your code to work?
It works (at least it doesn't raise Errors) with the sample (copy/paste of what you shared + a couple of other records I added for testing) in the workbook I shared. IMHO you go a bit too fast if I may. You know what you have (your actual data) and know +/- exactly what you expect. On the other hand helpers on forums have to understand... And until they get the right understanding + some representative actuals chances are high that they shoot in the dark#1 My goal is to see the data in 1 row/multiple columns for each Source Column
In principle I understand what you want to do but let's confirm with a single set of records in A1:F5 below:#1.1 The Source Column you talk about is the one highlighted in dark orange (col. C) ???
#1.2 Data in A3:C3 are "ignored"/shouldn't be reported ???
#1.3 Expected result in A1:O2 ???
#1.4 A few other ??? in attached file sheet Source#2 "There weren't enough elements in the enumeration to complete the operation."
Many possibilities. I tried a few scenarios but none failed with that error so it's hihgly probable your actual data are not consistently structured as what you initially shared and/or exceptions exist in the dataset. Attach (if not allowed share with OneDrive, Google Drive... and post the shared link) a representative workbook that raises the error please#3 The blank rows are not needed
OK, revised accordingly
- peiyezhuBronze Contributor
how about sql?
create temp table aa as select fillna(iif(rowid=1 or length(f01)<2,rowid,'')) grp,* from 基础堆叠转二维; select * from aa; select colIndex[0:3],group_concat(f04||'</td><td>'||f05||'</td><td>'||f06,'</td><td>') detail from aa where length(f01)>2 group by grp;
- peiyezhuBronze Contributor
I don't think I can use sql in power query or am I wrong?
You are right.
You can not use sql in power query.
It is online sql.
Please let me know if you know of a solution using the Power Query UI?
Sorry,I do not konw any solution using the Power Query.
- peiyezhuBronze Contributor
add blank row.
create temp table aa as select fillna(iif(rowid=1 or length(lag(f01) over())<2,rowid,'')) grp,iif(length(f01)<2,'g'||rowid,'') grp2,* from 基础堆叠转二维; select * from aa; select colIndex[2:4],group_concat(f04||'</td><td>'||f05||'</td><td>'||f06,'</td><td>') detail from aa group by grp,grp2;
f01 f02 f03 detail
S_DB1 S_Table1 S_Column1 T_DB1 T_Table1 T_Column1 T_DB2 T_Table2 T_Column2 T_DB4 T_Table4 T_Column4 T_DB6 T_Table6 T_Column6 S_DB3 S_Table3 S_Column3 T_DB3 T_Table3 T_Column3 T_DB7 T_Table7 T_Column7 T_DB9 T_Table9 T_Column9