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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Jedrzej
New Member

Table transformation

Hi,

I would like to ask for help with an assignment, today is the first time I am using such advanced PowerQuery functions in this M.

I have a graph like this:

start.jpg

and I need to get that result:

Jedrzej_0-1653487213329.png

I tried to do this by cutting text or elements from the table, but each time it returned a result only for EN and for the rest empty cells or an error. When I enter the language to filter in the code, it filters fine, but if I select it to filter using the LANGUAGE column, it only returns the first result.

 

Thank you for your help!

 

EDIT:

I solved the problem. The problem was the space character in the LANGUAGE cells because by default they are in one cell as [PL, US, DE]. When split into rows I was getting:[PL], [ US] and [ DE]. Where at the next ones there was a space at the beginning. After removing the space and applying the code:

Text.Combine(List.FindText(Text.Split([FIRST],"#(lf)"), [LANGUAGE]&":"))&
"#(lf)"&
Text.Combine(List.FindText(Text.Split([SECOND],"#(lf)"), [LANGUAGE]&":"))

I got the expected result

1 ACCEPTED SOLUTION

I solved the problem. The problem was the space character in the LANGUAGE cells because by default they are in one cell as [PL, US, DE]. When split into rows I was getting:[PL], [ US] and [ DE]. Where at the next ones there was a space at the beginning. After removing the space and applying the code:

Text.Combine(List.FindText(Text.Split([FIRST],"#(lf)"), [LANGUAGE]&":"))&
"#(lf)"&
Text.Combine(List.FindText(Text.Split([SECOND],"#(lf)"), [LANGUAGE]&":"))

I got the expected result

thanks for your help!

View solution in original post

3 REPLIES 3
rohit_singh
Solution Sage
Solution Sage

Hi @Jedrzej ,

Please try the following:

 

1) Assuming your data looks like this, please load this into power query.

rohit_singh_1-1653491433012.png

 

2) Fill down values on the "NUMBER" and "LANGUAGE" columns

rohit_singh_2-1653491454762.png

 

3) Merge columns "FIRST" and "SECOND" to create a new column "Merged", using "-" as the delimiter

rohit_singh_3-1653491558744.png

 

4) Add a custom column that compares "LANGUAGE" with 1st two characters of "Merged". If there is a match it returns the column value of "Merged" else null

rohit_singh_4-1653491642472.png


5) Remove column "Merged" and filter column custom <> null

rohit_singh_5-1653491697240.png

 

6) Split column "Custom" by delimiter "-". You will now see two columns "Custom.1" and "Custom.2"

rohit_singh_6-1653491764643.png


7) Add column to merge values of "Custom.1" and "Custom.2" into a list.

rohit_singh_7-1653491838023.png

 

😎Remove columns "Custom.1" and "Custom.2" and expand column "Custom"

rohit_singh_8-1653491862997.png

 

This is the final result

rohit_singh_9-1653491904773.png

 

Here is the M-Code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrwARNWUDJWJ1oJyASi0GArBQ9PKCPY1VUh0j8USdrF1Uoh3NPHx9vf19fVDyrg4Roa4gpWZATWSBOjjcEi1Dc6FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [NUMBER = _t, LANGUAGE = _t, FIRST = _t, SECOND = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"LANGUAGE"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"NUMBER", Int64.Type}, {"LANGUAGE", type text}, {"FIRST", type text}, {"SECOND", type text}}),
    #"Filled Down" = Table.FillDown(#"Changed Type",{"NUMBER", "LANGUAGE"}),
    #"Merged Columns" = Table.CombineColumns(#"Filled Down",{"FIRST", "SECOND"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"Merged"),
    #"Added Custom" = Table.AddColumn(#"Merged Columns", "Custom", each if [LANGUAGE] = Text.Range([Merged],0,2) then [Merged] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Merged"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Custom] <> null)),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Filtered Rows", "Custom", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Custom.1", "Custom.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom.1", type text}, {"Custom.2", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each {[Custom.1],[Custom.2]}),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Custom.1", "Custom.2"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns1", "Custom")
in
    #"Expanded Custom"

 

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

I solved the problem. The problem was the space character in the LANGUAGE cells because by default they are in one cell as [PL, US, DE]. When split into rows I was getting:[PL], [ US] and [ DE]. Where at the next ones there was a space at the beginning. After removing the space and applying the code:

Text.Combine(List.FindText(Text.Split([FIRST],"#(lf)"), [LANGUAGE]&":"))&
"#(lf)"&
Text.Combine(List.FindText(Text.Split([SECOND],"#(lf)"), [LANGUAGE]&":"))

I got the expected result

thanks for your help!

Unfortunately, my initial data looks different.

NUMBERLANGUAGE FIRSTSECOND
1PL,US,DEPL:
US: HI
DE: WILLKOMMEN
PL:
US: SEE YOU
DE: HEUTE

in the LANGUAGE column, I separate to the rows after the "," and I get:

NUMBERLANGUAGEFIRSTSECOND
1PLPL:
US: HI
DE: WILLKOMMEN
PL:
US: SEE YOU
DE: HEUTE
1USPL:
US: HI
DE: WILLKOMMEN
PL:
US: SEE YOU
DE: HEUTE
1DEPL:
US: HI
DE: WILLKOMMEN
PL:
US: SEE YOU
DE: HEUTE

In the FIRST and SECOND columns, sentences are separated by the end-of-line symbol (#(lf)).

The contents of one FIRST cell is:
[EN: #(lf) US: HI #(lf) DE: WILLKOMMEN]

the problem is how to select the appropriate language versions from a single cell.

unfortunately splitting it into more rows like in the case of LANGUAGE is not an option, because it will extend the number of rows by about 5^30

Helpful resources

Announcements
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.