Conditional sum in Numbers (iWork) - iwork

I would like to ask how to sum values in one column.
Let say I have two columns Date and Amount and need to sum Amount for those rows that have non empty Date.
I am using Numbers from Apple (iWork).
I could have been able to figure out a workaround. Creating an other column temp=ISBLANK(Date) and use SUMIF(temp, TRUE, Amount). But it seems to me pretty ugly. I want something like SUMIF(ISBLANK(Date), TRUE, Amount) which doesn't work.
Thanks for any replies.

Try SUMIF ( 'DATE', "=" & " ", 'Amount')
What this does is test that a Date value is not blank, using the = operator and a blank, as a concatenated string. I don't know why the concatenated string form works but the direct form ( "= " ) doesn't,

I was looking to sum rows WITH an empty cell (as opposed to the OP's non-empty cell), and this worked for me in Numbers 4.1 for Mac:
=SUMIF('DATE',"",'Amount')
That is, by making the condition simply an empty string, it summed only the rows that had empty strings in the DATE field.

Related

Copying contents of columns with Field calculator in Qgis

I have to split the content of a column into 2 differents columns using the QGIS Field Calculator. Basically, my table is something like that:
Basically I have to work with descriptio column omitting characters from 1-12 and then copy next 8 characters (in this case "AgilisSi") into the PresLACAGI column.
The other element to copy is the final number in descriptio column, ranging from 1 to 3 characters. Possibly the best is thing would be a syntax that reproduces in CodiClapa column the number after ": ", including the space in the syntax.
Thanks a lot!
Use the field calculator, check Update existing field and select column from drop down and type in the Expression window for:
PresLACAGI: substr(descriptio,12,8)
CodiClapa: right(descriptio,3)

Range values in Tableau

I want to visualise the below excel table in Tableau.
When adding this table to Tableau it shows Salary values as String and thus under Dimension Tab and not under Measure, thus cannot make proper graph from it.
How to convert this Salary range values to Int ?
As #Alexandru Porumb suggested, the best solution is to have a min_salary column and a max_salary column — unless you really have the actual salary available which is even better.
If you don’t want to revise the incoming data, you can get the same effect using the Split() function in a calculated field from Tableau to derive two integer fields from the original string field.
For example, you could define a calculated field called min_salary as INT(SPLIT([Salary], ‘-‘, 1)). Split() extracts part of a string based on a separator string. Int() converts the string to an integer.
You could simplify the way it sees the data and separate the salary column into Min and Max, thus you wouldn't have the hyphen that makes Tableau consider the entry as a string.
Simplistic idea, I know but it may help until a better solution will be provided.
Hope it helps

Rounding to a variable number of decimal places in SSRS

I am trying to find a way to round a field in SSRS to a dynamic number of decimal places. I know I can format it dynamically, and it may eventually come to that, but many of my users are going to take this report directly to Excel and are going to want to have actual numeric fields.
My t-SQL code includes these declared variables:
NumLong01 DECIMAL(23,8)
, NumLongDP01 INTEGER
The first set of entries in this table is for headers and rounding parameters. So I add values for these two as:
NULL
,4
and then I add the actual table values as:
543210987654321.87654321
,NULL
That way I can put a whole series of numbers into the table but they all have to be formatted the same way.
Running this query yields:
When I go to ReportBuilder, my field has this expression:
=Fields!NumLong01.Value
If I want to format a certain number of decimal places, I can just do this:
=Round(Fields!NumLong01.Value,2) or some such. What I tried to do, though, was to make it dynamic:
=Round(Fields!NumLong01.Value,First(Fields!NumLongDP01.Value, "DataSet1"))
This ended up rounding to 0 decimal places. I subsequently learned--by just using the second half in my field--that this was a NULL value. So I tried Sum instead of First--again, just in my field--and got the 4 that I expected. Great, so now I had my number, and I just put that in as my rounding:
=Round(Fields!NumLong01.Value,Sum(Fields!NumLongDP01.Value, "DataSet1"))
Only problem is, this yields an error. Next I asked myself if maybe it wasn't seeing this as a number for some reason. So i just added it onto my field. No problems. So I really don't know what it's doing. Is it thinking that this field might become so long that it will round to an illegal number of decimals places?
Now, I can do this:
=IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 8,Round(Fields!NumLong01.Value,8),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 7,Round(Fields!NumLong01.Value,7),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 6,Round(Fields!NumLong01.Value,6),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 5,Round(Fields!NumLong01.Value,5),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 4,Round(Fields!NumLong01.Value,4),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 3,Round(Fields!NumLong01.Value,3),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 2,Round(Fields!NumLong01.Value,2),IIf(Sum(Fields!NumLongDP01.Value, "DataSet1") = 1,Round(Fields!NumLong01.Value,1),Round(Fields!NumLong01.Value,0)))))))))
...and that works. But it seems like such a ridiculous way to go about it.
I'm also comfortable passing only rounded numbers out of t-SQL. But then I run into the problem of showing only a certain number of decimals on the report, because in the number formatting it doesn't allow for a dynamic number of decimal places for some reason.
Any ideas would be appreciated.
This isn't an exhaustive list of ways to accomplish dynamic rounding or number formatting as you can achieve this using custom code in the report or by adapting your dataset's SQL query.
Using Rounding:
The first set of entries in this table is for headers and rounding parameters. That way I can put a whole series of numbers into the table but they all have to be formatted the same way.
To avoid building expressions in your report that require aggregate functions such First and Sum and generating a blank row that you then have to remove, consider just entering the number of decimal places for every row instead of using a header row. The costs (storage and expression evaluation) are low even if it seems redundant.
This means that instead of using: =Round(Fields!NumLong01.Value,First(Fields!NumLongDP01.Value, "DataSet1")) you can use =Round(Fields!NumLong01.Value,Fields!NumLongDP01.Value) either as an expression or as a calculated field in DataSet1 or whatever your dataset is called.
Using Number Formatting:
But then I run into the problem of showing only a certain number of decimals on the report, because in the number formatting it doesn't allow for a dynamic number of decimal places for some reason.
You can define custom formatting for the NumLong01 field in the report and make it dynamic using an expression to build your custom formatting string.
Open the Text Box Properties for the NumLong01 textbox or tablix field
Open Number tab and select Custom from the Category list
Click the fx button and use the following expression ="0." + StrDup(First(Fields!NumLongDP01.Value, "DataSet1"), "0")
Using your example data, this expression would produce the custom formatting string 0.0000 which changes 543210987654321.87654321 to 543210987654321.8765. For your information, StrDup duplicates the specified string X number of times.
In cases where the fractional part of the number is less than the decimal precision required, this formatting string will pad it with 0s. If that's not desired, change the string to be duplicated to "#" like so: StrDup(First(Fields!NumLongDP01.Value, "DataSet1"), "#").
You can also use this method as a calculated field in the dataset but only if you have removed the header row and are entering the decimal places for every row as mentioned earlier. This is because you can't use the aggregate function in the calculated field expression.
To do this, add a calculated field to your dataset with the expression: =Format(Fields!NumLong01.Value, "0." + StrDup(Fields!NumLongDP01.Value, "0"))

How to concatenate 3 columns into one in a Matlab Table?

I have a Matlab table with three columns: Year, Month, Day.
I want to make it into one column that represents the date in a format 'MM/dd/yyyy'. How can I do that? I tried quite a while to no avail, but I believe someone may know it immediately.
Suppose you have a table with three columns with your values. As your table must contain the same type of data, you must first make sure that your values for the month, day and year are in the string format. If they aren't, convert them into strings (use B(:,1)=int2str(A(:,1)) for example)
Once your data in the string table, concatenate them in a 4th column.
for i=1:length(B(:,1))
B(i,4)=strcat(B(i,1), "/", B(i,2), "/", B(i,3));
end

SSRS and string parsing to produce a report

A friend told me that his new employer needs an SSRS report that parse a column that contains n consecutive occurrences of
1) the literal "Date:"
2) An optional separator character
3) followed by a date in DD-MM-YY format (leading zeros are optional)
4) a separator space
5) A single "WORD" of data that is associated with the date. This word will have no embedded spaces.
I'll populate a Sample table with data that meets this critera to give you an example to make it clear:
CREATE TABLE [dbo].[Sample](
[RowNumber] [int] NOT NULL,
[DataMess] [varchar](max) NOT NULL
) ON [PRIMARY]
INSERT [dbo].[Sample] ([RowNumber], [DataMess]) VALUES (1, N'Date:12-21-13 12/13/14/15 Date:4-2-11 39/12/134/14 Date:4-1-13 19/45/5/12')
INSERT [dbo].[Sample] ([RowNumber], [DataMess]) VALUES (2, N'Date:7-21-13 12/13/14/15 Date:8-21-12 39/12/34/14 Date:12-1-13 19/4/65/12')
INSERT [dbo].[Sample] ([RowNumber], [DataMess]) VALUES (3, N'Date:3-21-13 12/11233/14/15 Date:4-28-13 39/12/34/14 Date:9-19-13 19/45/65/12')
For the first record, "12/13/14/15" is considered to be the "Word" of data that is associated with the Date 12-21-13.
He was aked to produce the following report in SSRS:
Row Number DataMess
1 Date: 12-21-13 12/13/14/15
Date: 4-1-13 19/45/5/12
Date: 4-2-11 39/12/134/14
2 Date:12-1-13 19/4/65/12
Date:7-21-13 12/13/14/15
Date:8-21-12 39/12/34/14
3 Date:9-19-13 19/45/65/12
Date:4-28-13 39/12/34/14
Date:3-21-13 12/11233/14/15
Note that the Dates for each source row number are sorted in descending arder alomng with the associated wor of data.
I don't know SSRS, but my reaction was to recommend to him that he not even attempt the task but to tell his employer that the data shouldn't really be trying to do all of that ugly string parsing with T-SQL. Instead this repeating "Date: DATA" should be stored in individual child records that are associated with a parent Row record. I believe that the code would be ugly, inefficient, brittle and hard to maintain. What are your thoughts?
Assuming that management\client is always right or to conceed that "ideally" this is correct, but "for now" we need a SQL that produces the following report, how would one do this? The expectation was that this can be produced quickly ( a half day, for example)
You are of course correct, it's certainly far from the best way of storing the data. Any way of extracting the data for this report will be much more complex than it would be if it was stored differently.
However, based on the data it still wouldn't be too tough to actually generate the report. Due to the table structure actually generating the dataset for the report would be the hardest part.
So to generate the dataset, you need to split the data in DataMess to get one row per Date/Word, and be able to extract the date from that split data to be able to order by date as required.
Take your pick on how you want to split the data:
Split function equivalent in T-SQL? has many options, as does this link - Best Split Function.
Here's a SQL Fiddle with one of the functions in action.
Once you've split the data, use the appropriate function to extract the date portion, i.e. between the colon and the space before the word data, then CAST this as a date.
Once you've actually got the dataset, it's the most trivial of reports - just add a row group based on RowNumber, add the split Date/Word data as a detail field and you're done. Make sure the dataset is ordered by the extracted date field, even though you don't actually display this in the report.
As an interim measure I would certainly expect this to be doable in half a day of work or so. So for just this report it's not too bad, but for anything else you'll probably have trouble.
For a few rows it will likely run fine, but on any non-trivial sized dataset performance will be suboptimal.
Thank you. Here's what I did for the remaining part to get the dates sorted in DESC order.
SELECT
RowNumber
,'Date: ' + ss.Item AS Data
--,cast(substring(ss.Item, 1, charindex(' ' , ss.Item) ) AS date)
FROM
Sample s
CROSS apply dbo.SplitStrings_XML(s.DataMess,
N'Date:') ss
WHERE
Item IS NOT NULL
ORDER BY
rownumber,
cast(substring(ss.Item, 1, charindex(' ' , ss.Item) ) AS date) desc
If the data fails to hold up to this expected format and we encounter a date that is not valid, then the whole report blows up.