Power Query - concatenate column titles if there is a value

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have twenty there columns and I and trying to create a column that will list the column title if that column in that row has a value > 0

If [1q4] >0 then "1q4"
if [5q9] >0 then "5q9"

But I don't want to do an else because if both have a value I need the value in the new column to be 1q4 and 5q9 and so on.


Here is my end goal.
I need to sum the values in 1q4 and 5q9 only for rows where there is a value in both. But the catch is I need to be able to do this in many scenarios like if there is values in 1q4 and 75q99 then sum the rows where there is a value in both.

the "1q4" is a quantity range. I have 23 columns that have the range 1q4, 5q9, 10q24......

So Im thinking that if I have one column that concatenates the title name, if they have a value, I can then create another formula that checks this new column to see if it contains the two ranges I am comparing

I realize this may be confusing, by I can have so many variations I would need to create over 200 individual tables if I did not one by one. And then I would need to append all of them with would take the query forever to run.

I am hoping that my idea if concatenation will eventually lead me to an efficient query or two.


Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
@gheyman, can you share a sample here? It's not that clear to me what you are after.

I 'm thinking Table.CombineColumnsToRecord is a good starting point.
 
Upvote 0
Created this starting point to have a sample, hoping I got it right.
Book1
ABCDEFGHIJKLMNOPQRSTUVWX
1Other Column1q45q910q2441q37q321q340q349q320q32q313q343q335q330q345q316q338q337q326q342q32q2020q994q41
2a21844142032449121014175011943221259261423489136320446384264178264
3b48525402774483714472664003974262814549176111155304473488398146
4c23139423832242154298415160431888232400336496012100149
5d4752091738270402290000381502971750321110470415277370381
6e223439377368325305829528442111216524730130455122001816175349
7f134468159260371990511481072553536813614122445147475023490314
8g21299112483254359445111401592013341115459903719531748451
9h913894202603291654422534444311765513835813138742903139812564399
10i34620725434518015662442482387213101961593313502274622531526665428
11j750484234732072564529293197166309439186353279356155407427390365
12k35025042742133704612323138846648017614536128001173072874730455
13l49817549647137425430717800000016343003932788556379249
14m424244223112124204193342022613449716114521743948135538844938010937
Sheet2

First PQ attempt:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Columns Not zero", each
let
Record = Table.LastN(Record.ToTable(_),23),
Value_not_zero = Table.SelectRows(Record, each [Value] >0),
Cols = Value_not_zero[Name]
in
Text.Combine(Cols, ", "))
in
    #"Added Custom"
 
Upvote 1
Solution

Forum statistics

Threads
1,223,375
Messages
6,171,738
Members
452,419
Latest member
mapa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top