Concatenate sum with format, where fields can be nothing - reporting-services

In one textbox I need to concatenate the sum of the masses, if the units of measurement are grams and liters. Sometimes it happens that there are fields only with grams, or only with liters. Now in the textbox display like 0.0 l or g in this case.
My expression right now
=format(sum(iif(Fields!uom.Value = "l", 0, Fields!qty.Value)), "### ### ###0.0") & " g;"
& vbcrlf & format(sum(iif(Fields!uom.Value = "g", 0, Fields!qty.Value)),"### ### ###0.0") & " l"
It is necessary that if there are no fields with such a unit of measure, it is not displayed in the textbox.

Related

Excel: How to set a dropdown list cell to fetch list of strings from an API JSON response

I want a cell in Microsoft Excel (of type: dropdown list of strings) to fetch data from -
an API endpoint returning JSON response of array of strings (this format can be changed)
eg. response:
[
"Oranges",
"Apples",
"Mangoes"
]
I want something like : Set the formula of the cell to FetchList("localhost:8080/api/v1/list").
(FetchList is randomly written.)
How can I get started to achieve this ?
Thanks for any help!
One way to do this with Office 365 is place a formula somewhere in your workbook that contains the values that you want to present in the dropdown and then refer to that formula.
The formula would be:
= TRANSPOSE(
TEXTSPLIT(
SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( J2, """", "" ), "[", "" ), "]", "" ),
"," ) )
Where J2 contains the JSON string ["Oranges","Apples","Mangoes"] that you fetched. (i.e. the result of "localhost:8080/api/v1/list")
If you put that in cell D2 for example, then you can go to Data > Data Validation and choose List with the formula being =$D$2#.
A more readable version of the formula might be:
=LET( s, J2,
s_cln, SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( s, """", "" ), "[", "" ), "]", "" ),
TRANSPOSE( TEXTSPLIT( s_cln, "," ) ) )

Latex table from CSV file

The following code for creating Latex table from csv file is missing horizontal line on top of the table.
\documentclass{article}
\usepackage{csvsimple}
% Make csv in question
\begin{filecontents*}{check.csv}
labels,names,A,C,V,tools
a,example,838,663,683,
b,otter,353,215,192,
d,\textbf{broccoli},79,79,117,
e,fibredensityandcrosssection,1086,849,868,
ad,hcp-prefree:exec-centos7.freebuild-centos4-latest,70,76,157,
ar,shots47s\_fmriprep-1.2.3,,,,453
\end{filecontents*}
\begin{table*}[!ht]
\csvreader[%
tabular={|c|c|c|c|c|c|},
table head = \textbf{Labels} &\textbf{{names}} & \textbf{A} & \textbf{C} & \textbf{V} & \textbf{T}\\\hline,
late after line= \\,
late after last line=\\\hline %
]{check.csv}{labels=\labels,names=\names,A=\A,C=\C,V=\V,tools=\tools}%
{\labels & \names & \A & \C & \V & \tools}
\centering
\caption{\label{table1}Number by category}
\end{table*}
\end{document}
How we can add top horizontal line on top of table?
Please note that building such a data prison is bad style. Have a look at http://betterposters.blogspot.de/2012/08/the-data-prison.html , https://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf or https://wiert.me/2014/04/03/andre-vatter-google-wie-tabellen-eigentlich-aussehen-sollten-%EF%BB%BF/ for some guides about nice looking tables.
\documentclass{article}
\usepackage{csvsimple}
% Make csv in question
\begin{filecontents*}{check.csv}
labels,names,A,C,V,tools
a,example,838,663,683,
b,otter,353,215,192,
d,\textbf{broccoli},79,79,117,
e,fibredensityandcrosssection,1086,849,868,
ad,hcp-prefree:exec-centos7.freebuild-centos4-latest,70,76,157,
ar,shots47s\_fmriprep-1.2.3,,,,453
\end{filecontents*}
\begin{document}
\begin{table*}[!ht]
\csvreader[%
tabular={|c|c|c|c|c|c|},
table head = \hline\textbf{Labels} &\textbf{{names}} & \textbf{A} & \textbf{C} & \textbf{V} & \textbf{T}\\\hline,
late after line= \\,
late after last line=\\\hline %
]{check.csv}{labels=\labels,names=\names,A=\A,C=\C,V=\V,tools=\tools}%
{\labels & \names & \A & \C & \V & \tools}
\centering
\caption{\label{table1}Number by category}
\end{table*}
\end{document}

SSRS Format seconds as time (negative seconds)

I have a column with integers: TotalSec that has seconds. It can be 0, negative or positive.
I have to format these seconds in a report. But cant get something working for the negative seconds.
My logic:
For 0 = Nothing,
For Positive format as HH:mm:ss
For Negative - ABS the value then format as -HH:mm:ss
=IIF(SUM(Fields!TotalSec.Value)=0, Nothing, IiF(SUM(Fields!TotalSec.Value)>0,
Format(DateAdd("s",SUM(Fields!TotalSec.Value), "00:00:00"), "HH:mm:ss"), "-" & Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I get an #Error for the Negative numbers. With the warning:
Warning 2 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘TotalSec.Paragraphs[0].TextRuns[0]’ contains an error: The added or subtracted value results in an un-representable DateTime. Parameter name: value
It worked like this:
=IIF(SUM(Fields!TotalSec.Value)=0,Nothing,IIF(SUM(Fields!TotalSec.Value)< 0,"-"&Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss"),Format(DateAdd("s",ABS(SUM(Fields!TotalSec.Value)), "00:00:00"), "HH:mm:ss")))
I cleaned up the previous answer:
=IIf(Fields!elapsed.Value < 0, "-", "+")
&
Format(
DateAdd(
"s",
Abs(Fields!elapsed.Value),
"00:00:00"
),
"HH:mm:ss" ' can be m:ss
)
The "+" is to keep the results lined up, and can be replaced with "" if desired.

IIF Statements with blank or alpha characters in MS Visual Basic

I have a field CODE_USER_2 that can be equal to 1.75, 2, 2.62, 3.75, 5.25, 6, OT(w/2 spaces, or __(4 spaces). If it is 1.75, 2, 2.62, 3.75, 5.25, 6 I would like corresponding weights to result (THIS PART WORKS).
If the field is __ or OT, I would like the equation to result with 0. I currently get #error with the following formula.
=IIf(Fields!CODE_USER_2_IM.Value= " " OR "OT " ,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895))
Please let me know if you have ideas!
You have to repeat "Fields!CODE_USER_2_IM.Value = " after the OR.
Or try this - less wordy but more obscure :
=IIf( ( " |OT |" ).Contains(Fields!CODE_USER_2_IM.Value + "|"
,0,Switch(Fields!CODE_USER_2_IM.Value=1.75,.629,Fields!CODE_USER_2_IM.Value=2,.67,Fields!CODE_USER_2_IM.Value=2.62,1.089,Fields!CODE_USER_2_IM.Value=3.75,1.767,Fields!CODE_USER_2_IM.Value=5.25,3.224,Fields!CODE_USER_2_IM.Value=6,3.895
, True , 0))
Always close out a Switch with:
, True , [default value] )
Also beware that matching in SSRS expressions is exact e.g. 2 spaces not = 4 spaces.

quadratic equation

Question: I have a program that solves a quadratic equation. The program gives real solutions only. How do I perform the quality testing of the program? Do you need to ask me for some extra input parameters?
Create test cases, and check the result of your program against the expected result (which is calculated externally) in the test case.
The test cases can cover several ordinary cases, together with special cases, such as when the coefficient is 0, or the discriminant is < 0, = 0, near 0. When you compare the result, make sure you handle the comparison properly (since the result is floating point numbers).
# "quadratic-rb.rb" Code by RRB, dated April 2014. email ab_z#yahoo.com
class Quadratic
def input
print "Enter the value of a: "
$a = gets.to_f
print "Enter the value of b: "
$b = gets.to_f
print "Enter the value of c: "
$c = gets.to_f
end
def announcement #Method to display Equation
puts "The formula is " + $a.to_s + "x^2 + " + $b.to_s + "x + " + $c.to_s + "=0"
end
def result #Method to solve the equation and display answer
if ($b**2-4*$a*$c)>0
x1=(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a))
x2=(-(((Math.sqrt($b**2-4*$a*$c))-($b))/(2*$a)))
puts "The values of x1 and x2 are " +x1.to_s + " and " + x2.to_s
else
puts "x1 and x2 are imaginary numbers"
end
end
Quadratic_solver = Quadratic.new
Quadratic_solver.input
Quadratic_solver.announcement
Quadratic_solver.result
end