I have numerical output from a Kusto/KQL query where I would like to format the output to have comma separations. I would also like to round to the nearest whole number. For instance, instead of 1000.2865 it would come out as 1,000. Is there any built-in KQL function to accomplish this? I checked the documentation but couldn't find it. I would hope to find something like this:
format_number(myNumberColumn, 0, "commaThousands")
Note: if it comes out as a string I'm fine with that, and I also realize the displayed output in Azure Data Explorer does visually format. But once I take the data outside of there I lose that formatting, like if I paste into Excel or use the query for a dashboard to show a key metric.
for rounding a number, you can use the round() function, the ceiling() function, the floor() function, or the toint() function.
formatting numbers, e.g. adding separating commas, would be best if done by the client application you're using to present the result (e.g. you mentioned Excel, which certainly has this feature for formatting numeric values in cells).
Related
When extracting data about an Ethereum wallet via the Etherscan.io API, after converting from JSON to CSV I end up with values like this:
562450260000000000
30174270000000000000
552758590000000000
988800000000000000
The first is 0.56245026 ETH, with a ton of trailing zeroes. The second however is 30.17427 ETH. That's the real trouble here. I can't figure out how to format this column of data so that Excel effectively starts from the right, skips the 10 trailing zeroes, then goes 8 more places, to put the decimal.
Ideally what I want to end up with is this:
0.56245026
30.17427000
0.55275859
0.98880000
The trailing truncation is easy, but placing the decimal properly (preferably without a messy formula that uses position and string manipulation for example to do it) is what I'm stuck on. Anyone know how to do that?
The huge numbers are the numbers you are looking but multiplied by 10e18.
You should just divide those huge numbers by 10e18 and you will get your desired numbers.
I'm working in Access 2010's SQL editor and I'm performing a calculation that results in a ratio.
I would like to display this ratio as a percentage using the SQL syntax editor, but as a number, not a string. I'd like to be able to paste out/export to Excel and not have to convert text to numbers.
Let's say this is my calculation:
OriginCount/DestinationCount AS MatchRate
I used the FORMAT function to make it appear as a percentage, but the result appears as a string. (Which I think is how the FORMAT function is designed to work)
FORMAT(OriginCount/DestinationCount,'Percent') AS MatchRate
Question 1: Is this possible using the SQL syntax editor?
Question 2: How do I do it?
Thanks!
How will you be using this data? It is standard to leave it as a double, EG: 0.02354, and then simply change the format of any control displaying that field.
Users should not being seeing tables or queries without them being the recordsource of a form, so this shouldn't be a problem.
That way, when exporting to Excel/Wherever else, it will properly display as a decimal number, and when viewing in Access, it will display as a Percentage 2.35%
The result of the FORMAT function in access is always in string format, so that would be expected behavior.
Did you try the CONVERT function instead?
https://msdn.microsoft.com/en-us/library/ms187928.aspx
Is there a way for a number to stay as a number and not a string even with the percent sign?
The reason I write a function in a query like:
Format(IIf([BDE MTOE CURRENT]=0,0,[PROJECTED OH]/[BDE MTOE CURRENT]),"Percent")
is so that I can output a complete report without having to do anything to it.
Microsoft Access (My version is 2007) changes it to a string.
You do not need to format the number in the SQL query. There is a formatting option for the values in Access reports:
If you are exporting the data to Excel there is a similar option for the Excel cells.
The bottomline is: numbers should stay numbers. That way they are better manageable: you can sort them, you can apply mathematical operations on them
Agreed. I have decided to keep numbers as decimals and will format the spreadsheet columns into percentage from MS Access using VBA. I kinda hoped I could do it all from SQL.
Excel 2007 - anytime I click AutoSum it shows 0, or anytime I use the formula to Sum it still gives me a 0.
This is a SQL Query that is imported by using Data-Connection-SQL Server and saved SQL Query in the workbook.
What gives that is keeping me from totalling?
It seems to me the most likely explanation is that what you are trying to add are strings. If so, with Error Checking activated (Formulas tab) little triangles (by default green) should be clear evidence.
These also provide an easy way to convert strings that look like numbers into numbers that Excel can add. Select a contiguous range starting with a cell requiring conversion and a warning sign should appear:
(not always top left). Click on the exclamation mark and on Convert to Number and hopefully the format of all cells in your selection will be converted so your SUM function behave as you would like.
Much less likely (because I don't see how you would have done) is that somehow you have acquired leading spaces and when entering data it was into a cell formatted as Text. The triangle warning would be the same but Number Stored as Text does no conversion. A formula such as:
=TRIM(A1)
should do however, though it does depend on the type of space (eg would not work for NBSP - though you should not acquire one of those from an SQL import).
There may be other possible causes but it seems best to try the above before alternatives.
I live in Brasil and decimal separators are commas. For a bunch of reasons, I use dots as decimal separators in SQL Server, which is different from Excel.
With that being said, I would like to know why the following query
select 1.0*5
is understood as text in Excel (if so), when copying and pasting, and dots are not converted to commas, while
select cast(1.0*5 as float)
is understood as float in Excel.
What is the type of result in the first query?
UPDATE
If the query were
select 1.1*5
the result of copy and paste in Excel cell would be 5.5. It is not possible to convert this to value in Excel.
While the second query would result in 5,5. I can use the use this value in Excel in an addition operation, for example.
If you're doing it directly IN Excel, it seems that your regional settings are not seeing that as an operation with a decimal, but rather text. If you change your regional settings to US, it would probably resolve it correctly.
The difference between the two is that you are literally telling the value to be cast differently than the default. So your regional setting is overridden.
Excel, as smart as it is, tends to make many assumptions that could be tied to any number of things. Sometimes you just have to deal with it.
In the end, your 2nd query is likely to produce better results.