最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powerbi - PowerQueryM: Looping cells and changing values - Stack Overflow

programmeradmin0浏览0评论

The following table needs to be manipulated:

        Col1 | Col2 | Col3 | Col4 | Col5 | Col6| Col7
 Line1: null | null | Plan | null | null | null| null
 Line2: null | null | 1    | 2    | 3    | 4   | null

The task is to take the value from Col3 Line1 and place it in front of each cell beginning from Col3 Line2 to Col6 Line2.

The result would look like

        Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | Col7
 Line1: null | null | Plan | null | null | null | null
 Line2: null | null | Plan1| Plan2| Plan3| Plan4| null

Do you have any idea?

The following table needs to be manipulated:

        Col1 | Col2 | Col3 | Col4 | Col5 | Col6| Col7
 Line1: null | null | Plan | null | null | null| null
 Line2: null | null | 1    | 2    | 3    | 4   | null

The task is to take the value from Col3 Line1 and place it in front of each cell beginning from Col3 Line2 to Col6 Line2.

The result would look like

        Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | Col7
 Line1: null | null | Plan | null | null | null | null
 Line2: null | null | Plan1| Plan2| Plan3| Plan4| null

Do you have any idea?

Share Improve this question asked Feb 5 at 15:19 Rasputin221Rasputin221 1771 silver badge12 bronze badges 4
  • 1 Thats it? It is always going to be a 2 row grid with 7 columns? Or are you going to tell us next there can be more rows, or more columns, etc – horseyride Commented Feb 5 at 16:06
  • You can write M-Code in the Advanced Editor using the Table.ReplaceValue function if your real data is similar to what you show. Please edit your question to show what you have tried, and where you have run into problems. – Ron Rosenfeld Commented Feb 5 at 18:51
  • @horseyride I alread tried something with each and ReplaceValue, but it didn't look right in any way, thats why I didn't post it. – Rasputin221 Commented Feb 7 at 8:45
  • @Ron Rosenfeld was nice enough to post an answer the might or might not work given the limited information you provided. Good luck – horseyride Commented Feb 7 at 10:53
Add a comment  | 

1 Answer 1

Reset to default 0

Depending on your actual problem, here is one method that might work for you:

Insert the code below after whatever step shows the table you showed in your question
Change #"Previous Step" to reflect the name of the actual Previous Step in your query:

...
   #"Prefix Col3 Line1" = Table.ReplaceValue(
        Table.Skip(#"Previous Step",1), //Return table except for first row
        #"Previous Step"{0}[Col3], // Value in Column 3 Line 1
        null,
        (x,y,z) as text=>y & x, //Combine Column 3 Line 1 with values in each row of the selected columns
        List.Range(Table.ColumnNames(#"Previous Step"),2,4)), //Array of the required Column Names

//Combine above with the original Line 1
    #"Add Back Line1" = Table.Combine({Table.FromRecords({#"Previous Step"{0}}), #"Prefix Col3 Line1"})
in 
    #"Add Back Line1"

#"Previous Step"

Result

发布评论

评论列表(0)

  1. 暂无评论