The following custom number format mask will produce the desired results without losing the accuracy of the underlying value.
[>999999]0.0,,\M;[>999]0.0,\K;0
![Million and Thousand number formats](https://i.stack.imgur.com/7Cjcl.png)
The relevant commands are named filter
and query
. (There are also pivot table reports that could be used for summarizing data.) The details of implementation vary based on:
- Whether your date strings like
2015-12-10
are formatted as strings or dates.
- Whether you want to have 0 for months where no transactions are recorded (if so, then you have to provide the list of months for the summary table manually).
I'll give a version that operates with dates as dates (as they ought to be stored) and outputs data for all months present in the table (so, a month with no records will be absent).
The formula assumes the data is in columns A and B. Its explanation is below.
=query(arrayformula({year(A1:A)&"-"&right("0"&month(A1:A),2), B1:B}), "select Col1, sum(Col2) where Col2 is not null group by Col1 order by Col1 asc label Col1 'Month', sum(Col2) 'Total'")
Preparation
The formula arrayformula({year(A1:A)&"-"&right("0"&month(A1:A),2), B1:B})
prepares a table for querying. The second column is just your B column. The first column is the month (as text) in format 2016-01. The slightly cumbersome right("0"&month(A1:A),2)
is there to get 01 rather than 1 for January.
Query
The query language is SQL-like. Here is the query string I used, with linebreaks:
select Col1, sum(Col2)
where Col2 is not null
group by Col1
order by Col1 asc
label Col1 'Month', sum(Col2) 'Total'
Here, Col1 and Col2 refer to the columns of the table prepared at the first step. The query selects months and the total for each month, sorting them in order. The labels are optional, inserted just to make the output look better.
Remark
If you don't want to have a long formula like that, the preparation step can be a separate formula, creating a helper table, which the query
command can then refer to.
Best Answer
You can use the
DOLLAR()
function to return a localized currency format.Like so:
If you still want to place your own currency symbol, then use
FIXED()
.