I am currently using a function in Column J as below
=ArrayFormula(IFERROR(Vlookup(if(U3:U<>"",(if(U3:U<5,"Hot",if(U3:U<10,"Warm",if(U3:U<30,"Cold",if(U3:U>30,"Lost"))))),),CellRef!A1:B,2,0)))
Column U contains Numerical data which return the value accordingly via vlookup,
But what if i want the function to look into Column L first and if data found return value, if nothing is found in Column L it should start looking into Column U.
p.s. Column L already contains text and not numbers
sheet link here
https://docs.google.com/spreadsheets/d/1dXZlC4i_l1WGCp6tbiXUFPhYBr3oc7b0V0sUbzG313M/edit?usp=sharing
Use ifs(), like this:
=arrayformula(
iferror(
vlookup(
ifs(
len(L3:L), L3:L,
V3:V = "", iferror(1/0),
V3:V < 5, "Hot",
V3:V < 11, "Warm",
V3:V < 30, "Cold",
V3:V >= 30, "Lost"
),
CellRef!A1:B,
columns(CellRef!A1:B),
false
)
)
)
See your sample spreadsheet.
Related
SHEET A - origin
Column A = ID
Column B = can contain "Accepted"(+ more text), "Rejected"(+more text), "Partially Accepted"(+ more text)
SHEET B - destination
Column A = Column A from Sheet A
Column B = If Column B from Sheet A = "Accepted*" return 1, "Rejected*" return 2, "Partially*" return 3, else return 4
WHAT I've tried so far:
a) Works but I can't make it into an array
=IF(COUNTIF(SHEETA!A2,"*Rejected*"),2,IF(COUNTIF(SHEETA!A2,"*Partially*"),3,IF(COUNTIF(SHEETA!A2,"Accepted*"),1,4)))
b) Been trying to make it work (simplified version) but it's not working
=if((VLOOKUP(A2,A2:B2,2,FALSE))="Rejected*","2","1")
Can anyone give me a hand?
Thank you in advance
try in row 2:
=INDEX(IFNA(VLOOKUP(A2:A, {SheetA!A2:A, IFNA(CHOOSE(MATCH(
REGEXEXTRACT(SheetA!B2:B, "(?i)accepted|rejected|partially accepted"),
{"accepted", "rejected", "partially accepted"}, ), 1, 2, 3), 4)}, 2, )))
Suppose I have a table as follows:
TableA =
DATATABLE (
"Year", INTEGER,
"Group", STRING,
"Value", DOUBLE,
{
{ 2015, "A", 2 },
{ 2015, "B", 8 },
{ 2016, "A", 9 },
{ 2016, "B", 3 },
{ 2016, "C", 7 },
{ 2017, "B", 5 },
{ 2018, "B", 6 },
{ 2018, "D", 7 }
}
)
I want a measure that returns the top Group based on its Value that work inside or outside a Year filter context. That is, it can be used in a matrix visual like this (including the Total row):
It's not hard to find the maximal value using DAX:
MaxValue = MAX(TableA[Value])
or
MaxValue = MAXX(TableA, TableA[Value])
But what is the best way to look up the Group that corresponds to that value?
I've tried this:
Top Group = LOOKUPVALUE(TableA[Group],
TableA[Year], MAX(TableA[Year]),
TableA[Value], MAX(TableA[Value]))
However, this doesn't work for the Total row and I'd rather not have to use the Year in the measure if possible (there are likely other columns to worry about in a real scenario).
Note: I am providing a couple solutions in the answers below, but I'd love to see any other approaches as well.
Ideally, it would be nice if there were an extra argument in the MAXX function that would specify which column to return after finding the maximum, much like the MAXIFS Excel function has.
Another way to do this is through the use of the TOPN function.
The TOPN function returns entire row(s) instead of a single value. For example, the code
TOPN(1, TableA, TableA[Value])
returns the top 1 row of TableA ordered by TableA[Value]. The Group value associated with that top Value is in the row, but we need to be able to access it. There are a couple of possibilities.
Use MAXX:
Top Group = MAXX(TOPN(1, TableA, TableA[Value]), TableA[Group])
This finds the maximum Group from the TOPN table in the first argument. (There is only one Group value, but this allows us to covert a table into a single value.)
Use SELECTCOLUMNS:
Top Group = SELECTCOLUMNS(TOPN(1, TableA, TableA[Value]), "Group", TableA[Group])
This function usually returns a table (with the columns that are specified), but in this case, it is a table with a single row and a single column, which means the DAX interprets it as just a regular value.
One way to do this is to store the maximum value and use that as a filter condition.
For example,
Top Group =
VAR MaxValue = MAX(TableA[Value])
RETURN MAXX(FILTER(TableA, TableA[Value] = MaxValue), TableA[Group])
or similarly,
Top Group =
VAR MaxValue = MAX(TableA[Value])
RETURN CALCULATE(MAX(TableA[Group]), TableA[Value] = MaxValue)
If there are multiple groups with the same maximum value the measures above will pick the first one alphabetically. If there are multiple and you want to show all of them, you could use a concatenate iterator function:
Top Group =
VAR MaxValue = MAX(TableA[Value])
RETURN CONCATENATEX(
CALCULATETABLE(
VALUES(TableA[Group]),
TableA[Value] = MaxValue
),
TableA[Group],
", "
)
If you changed the 9 in TableA to an 8, this last measure would return A, B rather than A.
I have a string column where I only need to the numbers from each string, e.g.
A-123 -> 123
456 -> 456
7-X89 -> 789
How can this be done in PowerQuery?
Add column. In custom column formula type this one-liner:
= Text.Select( [Column], {"0".."9"} )
where [Column] is a string column with a mix of digits and other characters. It extracts numbers only. The new column is still a text column, so you have to change the type.
Edit. If there are dots and minus characters:
= Text.Select( [Column1], {"0".."9", "-", "."} ))
Alternatively, you can transform the existing column:
= Table.TransformColumns( #"PreviousStepName" , {{"Column", each Text.Select( _ , {"0".."9","-","."} ) }} )
An alternative solution is to split the values on each number, and remove blanks from the resulting list.
This result can be used as a new list of delimiters to be used with function Splitter.SplitTextByEachDelimiter to split the original text again and combine the resulting list to the final result.
Explanation: Splitter.SplitTextByEachDelimiter first splits on the first delimiter in the list, then on the second and so on. Note that this function creates a function that must be called with the original string as parameter, so like S.S(delimiters)(string).
Example code:
let
Source = Table1,
NumbersOnly = Table.TransformColumns(Source,{{"String", (string) => Text.Combine(Splitter.SplitTextByEachDelimiter(List.Select(Text.SplitAny(string,"0123456789"), each _ <> ""))(string))}})
in
NumbersOnly
First, create a custom function in PowerQuery using New Query - From Other Sources -> Blank Query. Open the Advanced Editor and paste the following code:
(source) =>
let
NumbersOnly = (char) => if Character.ToNumber(char) >=48 and Character.ToNumber(char) < 58 then char else "",
Len = Text.Length(source),
Acc = List.Accumulate(
List.Generate( () => 0, each _ < Len, each _ + 1),
"",
(acc, index) => acc& NumbersOnly(Text.At(source, index))
),
AsNumber = Number.FromText(Acc)
in
AsNumber
Name this query NumbersOnly.
Now in your main query, add another calculated column where you call this NumbersOnly function with the source column, e.g.:
let
Source = Table.FromRecords({[text="A-123"], [text="456"], [text="7-X89"]}),
Result = Table.AddColumn(Source, "Values", each NumbersOnly([text]), Int64.Type)
in
Result
I am in the process of learning ColdFusion and I am trying to work with spreadsheets using spreadsheetFormatRows(spreadsheetObject, dataFormat, rangeOfRowsFormated)
How can I set the range to include all of the rows, except the header row, which is for column name? Is there a function that returns the number of the rows on cfspreadsheet object, so I can set the range to '2-rowCount'?
I tried spreadsheetFormatRows(theSheet, headerFormat, 2-50); and works fine and formats rows 2 to 50, but I don't want to have that hard-coded.
Thank you in advance.
The spreadsheet object has an attribute rowcount. You can do spreadsheetFormatRows(theSheet, format, "2-#theSheet.rowCount#");
<cfscript>
mySheet = spreadSheetNew("My Sheet");
spreadSheetAddRow(mySheet, "'Col. A','Col. B','Col. C'");
for(i=1; i <= RandRange(1, 100); i++){
spreadSheetAddRow(mySheet, "'Row A#i#','Row B#i#','Row C#i#'");
}
spreadSheetFormatRow(mySheet, {bold = true, fontsize = 24}, 1);
spreadSheetFormatRows(mySheet, {fontsize = 16}, "2-#mySheet.rowcount#");
cfheader(name = "Content-Disposition", value = 'inline; fileName="test.xls"');
cfcontent(type="application/vnd.ms-excel", variable="#spreadSheetReadBinary(mySheet)#");
</cfscript>
Try Online
Keep track of the number of rows as you populate them and save the value to a variable. Simpler yet, if they are query results, use the recordcount variable from cfquery.
Remember to add 1 so you format the last row.
I currently have Column Data formulated below in Power BI which I need for it to display in one column but replacing the "1" with a Text value being:
Orginal column formula:
Age (18-27) = IF(AND([Age]>17, [Age]<28),"1",BLANK())
Age (28-35) = IF(AND([Age]>27, [Age]<36),"1",BLANK())
Age (36-43) = IF(AND([Age]>35, [Age]<44),"1",BLANK())
Age (44-50) = IF(AND([Age]>43, [Age]<51),"1",BLANK())
Age (50+) = IF([Age]>50,"1 ", BLANK())
Output:
Age (18-27) = IF(AND([Age]>17, [Age]<28),"Age (18-27)",BLANK())
Age (28-35) = IF(AND([Age]>27, [Age]<36),"Age (28-35)",BLANK())
Age (36-43) = IF(AND([Age]>35, [Age]<44),"Age (36-43)",BLANK())
Age (44-50) = IF(AND([Age]>43, [Age]<51),"Age (44-50)",BLANK())
Age (50+) = IF([Age]>50,"Age (50+) ", BLANK())
I would like to have the formula display the data in one column where it is consolidating the Output formula (seen above) so I see the results in one column.
Just nest your IFs:
Age Group = IF(AND([Age]>17, [Age]<28),"18-27",
IF(AND([Age]>27, [Age]<36),"28-35",
IF(AND([Age]>35, [Age]<44),"36-43",
IF(AND([Age]>43, [Age]<51),"44-50",
IF([Age]>50,"50+", BLANK())
))))
You can use SWITCH() like this which is much cleaner than nested IFs:
Age Group = SWITCH(TRUE(),
AND([Age]>17, [Age]<28), "18-27",
AND([Age]>27, [Age]<36), "28-35",
AND([Age]>35, [Age]<44), "36-43",
AND([Age]>43, [Age]<51), "44-50",
[Age]>50, "50+", BLANK()
)
Source: https://community.powerbi.com/t5/Desktop/IF-or-SWITCH/m-p/167098#M72970
Another variation of the SWITCH TRUE pattern:
Age Group =
SWITCH (
TRUE (),
[Age] < 18, BLANK (),
[Age] <= 27, "18-27",
[Age] <= 35, "28-35",
[Age] <= 43, "36-43",
[Age] <= 50, "44-50",
[Age] > 50, "50+"
)
if you want to categorize the column value in the numerical range you can use below dax query.
bubble = IF(AND([no_of_days_pending]>=100, [no_of_days_pending]<200),150,
IF(AND([no_of_days_pending]>=200, [no_of_days_pending]<300),250,
IF(AND([no_of_days_pending]>=300, [no_of_days_pending]<400),350,
IF(AND([no_of_days_pending]>=400, [no_of_days_pending]<500),450,
IF([no_of_days_pending]>=500,600, BLANK())
))))