Running Excel query row by row - excel

I have made a following query in excel powerquery:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
IDname = Vir{0}[IDname],
query = "exec procOderBySampleID '"& IDname &"' ",
target = Sql.Database("XXX-YYYY\YY76", "SQLtable", [Query=query])
in
target
It returns result for a first row in IDname column. I would like a query to run row by row and return results for all the values in IDname column. Combining values with comma in between them IDname = Text.Combine(List.Transform(Source[IDname], Text.From), ", "), and passing them to query does not work, so the solution would need to work row by row.
Sample:
A1 IDname
A2 78-001
A3 78-002
A4 78-003
query should run stored procedure for one value after another (A2 then A3 then A4) and return a table:
A1 IDname Refnumber User
A2 78-001 4 Mat
A3 78-002 7 Kid
A4 78-003 5 Luc
With current code I only get A1 and A2 as result.

Related

Stacking pairs of columns in Excel with PowerQuery

I have a table generated in power query that is currently in the following format
A
Key1
Value1
Key2
Value2
A1
B1
C1
D1
E1
I want
A
Key
Value
A1
B1
C1
A1
D1
E1
How can this be achieved in power query?
Answer from Peter works, or to make it more generic:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
base=1, // # leading columns that will repeat
group=2, // followed by groups of 2 columns
Combo = List.Transform(List.Split(List.Skip(Table.ColumnNames(Source),base),group), each List.FirstN(Table.ColumnNames(Source),base) & _),
#"Added Custom" =List.Accumulate(
Combo,
#table({"Column1"}, {}),
(state,current)=> state & Table.Skip(Table.DemoteHeaders(Table.SelectColumns(Source, current)),1)
)
in #"Added Custom"
Reference the original table, remove columns 4 and 5 and rename the remaining columns to A, Key and Value.
Reference the original table again, remove columns 2 and 3 and rename the remaining columns to A, Key and Value.
Append the 2 above queries

Sum only cells with prefix letter in a row

I have data in Row 1 as follow:
A1 = 8
A2 = 9
A3 = CN2.75
A4 = CN3
I would like the result in cell B2 = sum range A1 to A4 and only sum cells with prefix letter "CN". The sum result in cell B2 should be = 2.75 + 3 = 5.75
=SUMPRODUCT(+IF(LEFT(A1:A4,2)="CN",1,0),IFERROR(VALUE(RIGHT(A1:A4,LEN(A1:A4)-2)),0))
Prefer even JvDV's Version from the comments, even more efficient
Enter as an array formula Ctrl+Shift+Enter

Excel Formula || How to count occurrences of a value in column

Need some help in figuring out an formula to count the number of times a value is listed in a column. I will try and explain the requirement below.
The below image show sample of data set.
The requirement is to list out issues and actions per customer.
As you can see, even from values clustered in cell, we need to find out individual unique values and then map it against the adjacent column or columns.
It just need an extra sheet/table to execute..
try :
A1 = a,b,c
A2 = b,c
A3 = c,b,a
A4 = c,a
A5 = b
B1 = ss
B2 = ss
B3 = dd
B4 = dd
B5 = ss
D1 = a
E1 = b
F1 = c
C7 = ss
C8 = dd
D2 =IF(FIND(D$1,$A2,1)>0,1,"") drag until F6
D7 =COUNTIFS($B$2:$B$6,$C7,D$2:D$6,1) drag until F8
D7:F8 will be your desired results. Happy trying.

Excel how to find values in 1 column exist in the range of values in another (approximate)

How can I search if values in one cell (column A) exist in column B. With an approximate threshhold of +/- .5
For instance:
Cell A2: 100.26
Column B: 100.30
Is there a formula that can search A2 within all of column B for an approximate match +/- .5 to return true/false?
You can use COUNTIFS() for this:
=COUNTIFS(B:B, "<" & A2 + 0.5,B:B, ">" & A2 - 0.5)
This tests values in Column B twice. Once to see if there is a value less then A2+.5 and then again to see if that value is also greater than A2 - .5
If you want this to return True/False, just turn it into an inequality:
=COUNTIFS(B:B, "<" & A2 + 0.5,B:B, ">" & A2 - 0.5)>0
Update with Example
To show this working, put value 10 in cell A2. Then in B1 though B5 put the following list:
1
4
10.2
20
24
Now in C1 (or any cell on the same tab that isn't A2 or in Column B) put the formula from above:
=COUNTIFS(B:B, "<" & A2 + 0.5,B:B, ">" & A2 - 0.5)>0
And it will spit out "True" because the value 10 that is in cell A2 is within +/-5 from a value that exists in Column B.
Add 2 helper columns C and D where C is =B1-0.5 and fill down and D is =B1+0.5 and filled down.
Then =if(and(a2>C2,a2<D2,TRUE,FALSE)

Excel - Find last same value in Column X and add Column Y to current cell

I have a sheet that includes (3) different sources of information, where the source is determined in ColumnA, MoneyOut = ColumnB, MoneyIn = ColumnC, and SourceTotal = ColumnD.
When working with a current row, how can I find the last row in which ColumnA = CurrentRowColumnA[Value], and sum(PrevColumnB[Value]+PrevColumnC[Value]) to CurrentRowColumnD[Value].
Ex:
A1 = Source1
B1 = 200
C1 = 200
D1 = 400
A2 = Source2
B2 = 300
C2 = 200
D2 = 500
A3 = Source1
B3 = 200
C3 = 600
D3 = 1200 (D1 + sum(B3+C3))
How can I write a function to do this continuous addition without having to do a different sumifs for each row?
I've tried:
Assuming I'm on D4...
=SUM(IF(A:A=$A4, B4+C4))+IF($A3=$A4, D3)
Which will work for the first few, but once there is another source, this formula doesn't work.
Should I be using an OFFSET() function?
Formula:
=SUMIF($A$1:$A1,$A1,$B$1:$B1)+SUMIF($A$1:$A1,$A1,$C$1:$C1)
Use this in your example sheet to get the result you want.

Resources