I'm using Google Gauges and would like to add a % sign after the value in the gauge. My values display with fine without the percent symbol (whole numbers 0 - 100), but when I start trying to add the percent symbol things get wonky.
Here's what I've tried
// Format the data to include % symbol
var formatter = new google.visualization.NumberFormat(
{suffix: '\u0025'}
//{suffix: '%'}
//{pattern: '#%'}
);
All three attempts display the correct visualization, but for the actual value text I get varying results.
Using either suffix method it adds two decimal places:
6 => 6.00%
26 => 26.00%
and so on
Using the pattern method it multiples the value by 100
6 => 600%
26 => 2600%
and so on
Any clue on how to simply display the value along with a percent symbol?
It's simpler than all that. If you just make a number formatter, specifying the pattern, and the suffix, you're all set:
http://jsfiddle.net/fHnnn/
Related
I want to make the following transformation to a set of datas in my google spreadsheets :
6 views -> 6
73K views -> 73000
3650 -> 3650
163K views -> 163000
1.2K views -> 1200
52.5K -> 52500
All the datas are in a column and depending on the case I need to apply a specific transformation.
I tried to put all the regex in one formula but I failed. I always had a case over two regular expressions etc.
Anyaway I end up making these regex one case by one case in different columns. It works fine but I feel like it could slowdown the sheet since I except a lot of data coming into this sheet.
Here is the sheet : spreadsheet
Thank you for your help !
Use regexreplace(), like this:
=arrayformula(
iferror( 1 /
value(
regexreplace(
regexreplace(trim(A2:A), "\s*K", "e3"),
" views", ""
)
)
^ -1 )
)
See your sample spreadsheet.
replace 'views' using regex: /(?<=(\d*\.?\d+\K?)) views/gi
To replace 'K' with or without decimal value, first, detect K then replace K with an empty string and multiply by 1000.
use call back function as:
txt.replace(/(?<=(\d*\.?\d+\K?)) views/gi, '').replace(/(?<=\d)\.?\d+K/g, x => x.replace(/K/gi, '')*1000)
code:
arr = [`6 views`,
`73K views`,
`3650`,
`163K views`,
`1.2K views`,
`52.5K`];
arr.forEach(txt => {
console.log(txt.replace(/(?<=(\d*\.?\d+\K?)) views/gi, '').replace(/(?<=\d)\.?\d+K/g, x => x.replace(/K/gi, '')*1000))
})
Output:
6
73000
3650
163000
1200
52500
Say your inputs are in column A. Empty cells allowed. In any other column,
=arrayformula(if(A2:A<>"",value(substitute(substitute(A2:A," views",""),"K","e3")),))
works.
Adjust the range A2:A as needed.
Also note that non-empty cells with empty strings are ignored.
Basically, since Google Sheet's regex engine doesn't support look around, it is more efficient to take advantage of the rather strict patterns in your application and use substitute() instead.
I have a Google Sheets cell containing a list of people attending an event. Some of the guests will bring friends. So the cell (A1) can look like this:
Ben, Sarah + 2, James , Mary + 5
I need to count the total number of people attending, which in this case is 11. And so I was thinking of using a formula along these lines:
=count(SPLIT(SUBSTITUTE(A1,"+",","),","))
But this doesn't work because it's only counting the numbers as 1 item, and the COUNT function doesn't appear to work.
How can I make this work, so that it correctly gives the number of attendees as 11?
You can use the following formula
=IF(LEN(A2),
SUM(COUNTA(SPLIT(A2,",")),
IFERROR(SPLIT(REGEXREPLACE(A2,"\D"," ")," "))),"")
Functions used:
IF
LEN
SUM
COUNTA
SPLIT
IFERROR
REGEXREPLACE
You can obtain the total sum by doing this:
=if(regexmatch(A1,"\+"),sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))),if(isblank(A1),"",counta(split(A1,","))))
Explanation:
if(regexmatch(A1,"\+"), something, if(isblank(A1),"",counta(split(A1,",")))) => if there are not + signs in the answer, then check if the cell is empty or not, if empty, print blank, else just count how many people are between commas, otherwise calculate with the plus ones. (explanation below)
split(A1,",")),"\+") => red area => will separate the cell by commas, and the result can be seen in the red area in the picture
split(TRANSPOSE(split(A1,",")),"\+") => green area => will loop through each of the results above and separate to a cell on the right the values that have a + sign between them, can be seen in the green area in the image
query(split(TRANSPOSE(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0) => blue area => then we will query the 2 columns, in the left one we want to count the number of rows in that column (the columns with the names), on the next column we want to sum the values (the plus ones)
sum(ArrayFormula(query(split(transpose(split(A1,",")),"\+"),"select count(Col1), sum(Col2)",0))) => yellow area => then we will sum the values of the 2 columns to get the final result
This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 1 year ago.
I want to make a number format in Google Sheets that turns large numbers into their abbreviated form. Example: "1 200" -> "1.2k", "1 500 000 000 000 000" (one point five quadrillions) -> "1.5Qa". I have absolutely no idea on how would that look.
Thanks in advance.
this should cover your needs:
=ARRAYFORMULA(IF(A:A<10^3, A:A,
IF(1*A:A<10^6, TEXT(A:A/10^3, "#.0\k"),
IF(1*A:A<10^9, TEXT(A:A/10^6, "#.0\M"),
IF(1*A:A<10^12, TEXT(A:A/10^9, "#.0\B"),
IF(1*A:A<10^15, TEXT(A:A/10^12, "#.0\T"),
IF(1*A:A<10^18, TEXT(A:A/10^15, "#.0\Q\a"),
IF(1*A:A<10^21, TEXT(A:A/10^18, "#.0\Q\i"),
IF(1*A:A<10^24, TEXT(A:A/10^21, "#.0\S\x"),
IF(1*A:A<10^27, TEXT(A:A/10^24, "#.0\S\p"),
IF(1*A:A<10^30, TEXT(A:A/10^27, "#.0\O"),
IF(1*A:A<10^33, TEXT(A:A/10^30, "#.0\N"),
IF(1*A:A<10^36, TEXT(A:A/10^33, "#.0\D"),
IF(1*A:A<10^39, TEXT(A:A/10^36, "#.0\U"),
IF(1*A:A<10^42, TEXT(A:A/10^39, "#.0\D\d"),
IF(1*A:A<10^45, TEXT(A:A/10^42, "#.0\T\d"),
IF(1*A:A<10^48, TEXT(A:A/10^45, "#.0\Q\a\d"),
IF(1*A:A<10^51, TEXT(A:A/10^48, "#.0\Q\u\d"),
IF(1*A:A<10^54, TEXT(A:A/10^51, "#.0\S\x\d"),
IF(1*A:A<10^57, TEXT(A:A/10^54, "#.0\S\p\d"),
IF(1*A:A<10^60, TEXT(A:A/10^57, "#.0\O\d"),
IF(1*A:A<10^63, TEXT(A:A/10^60, "#.0\N\d"),
IF(1*A:A<10^66, TEXT(A:A/10^63, "#.0\V"),
IF(1*A:A<10^69, TEXT(A:A/10^66, "#.0\C"), ))))))))))))))))))))))))
Use a custom number format
Select the range of cells you want to convert
Go to Format -> Number -> More Formats -> Custom number format
Paste into the input field [>999999]#,,"M";#,"K"
Click on Apply - Done
I do not think it is possible to configure more than two formats of a cell to adapt dynamically according to the number inside it without some scripting. That would be nice as it would preserved the number type.
But if there is no need to preserve the number type and string is acceptable, then strings could be generated like this using TEXT function and dynamically setting format for the number based on a reference:
=INDEX(
TEXT(
E2:E24,
"0.0"
& IFNA(
REPT(",", (VLOOKUP(INT(LOG10(E2:E24)), $C$2:$C$8, 1, TRUE)) / 3)
& "\" & VLOOKUP(INT(LOG10(E2:E24)), {$C$2:$C$8, $A$2:$A$8}, 2, TRUE)
)
)
)
On the left you can see a reference columns where I used symbols from wiki.
I have a Actuals column like so:
ID | Airport
------------
A | 98.4
B | 98.0
C | 95.3
I'm attempting to format the numbers above into percentages for a front-end report. I have this written in a switch statement - for ease I'll just write the logic as an IF boolean.
example_measure =
VAR Nums = SELECTEDVALUES(Table[Actuals])
VAR FormatNums = IF(DIVIDE(ROUND(nums,1), nums) = 1,
format(nums,"0%"),format(nums,"0.0%")
-
RETURN
FormatNums
no matter what I do this always returns a number with a floating point value of 1f
so in my raw data of 98.0 I'm expecting the format to return "98%" rather than "98.0%"
the measures are used on individual cards, and are filtered so they can only ever show one value or blank, meaning they will only ever display one value on their own.
I've toyed with using if(nums = int(nums) which should evaluate to true for 98.0 but it I always get false.
There is a simpler way - just use built-in formatting codes:
Formatted Actuals =
VAR x = SELECTEDVALUE(Data[Actuals])
RETURN
FORMAT(x, "General Number") & "%"
Result:
Built-in style "General Number" handles your situation correctly, you just need to add % symbol to the formatted string. No need to test for whole numbers.
To convert a column/measure into percentage, you can simply divide the column by 100 and then format it as a percentage. Use the following steps:
Create a new column/measure: Perc_value = Table[Actuals]/100
Then go into the modelling tab, select the created column/measure and format it as a % and limit the number of decimal places to 0
This should give the view you are looking for. Hope this helps.
Edit:
You can use the below formula to achieve the desired result:
Column4 = IF('Table'[Column2]-ROUND('Table'[Column2],0)=0,FORMAT('Table'[Column2]/100,"0%"),FORMAT('Table'[Column2]/100,"0.0%"))
Replace Column2 withyour field and you should be good to go.
I'm am exploring methods of giving scores to different datapoints within a dataset. These points come from a mix of numbers and text string attributes looking for certain characteristics, e.g. if Col. A contains more than X number of "|", then give it a 1. If not, it gets a 0 for that category. I also have some that give the point when the value is >X.
I have been trying to do this with =IF, for example, =IF([sheet] = [Text], "1","0").
I can get it to give me 1 or 0, but I am unable to get a point total with sum.
I have tried changing the formatting of the text to both "number", "plain text", and have left it as automatic, but I can't get it to sum. Thoughts? Is there maybe a better way to do this?
FWIW - I'm trying to score based on about 12 factors.
Best,
Alex
The issue here might be that you're having the cell evaluate to either the string "0" or the string "1" rather than the number 0 or the number 1. That would explain why you're seeing the right things but the math isn't coming out right - the cell contents look like numbers, but they're really text, which the summation would then ignore.
One option would be to drop the quotation marks and write something like this:
=IF(condition, 1, 0)
This has the condition evaluate to 1 if it's true and 0 if it's false.
Alternatively, you could write something like this:
=(condition) * 1
This will take the boolean TRUE or FALSE returned by condition and convert it to either the numeric value 1 (true) or the numeric value 0 (false).