I'm trying to filter my parameters in a condition where I have it choose a record when a multiple selection ListBox is selected. If a person doesn't select a record it by default chooses the "Not Selected" option. The issue is:
=IIF(
InStr(Join(Parameters!ProvinceID.Value,”,”),0),
True,
IIF(
InStr(Join(Parameters!ProvinceID.Value,”,”),
Fields!ProvinceID.Value
)<>0,
True,
False)
)
The result wont allow the Proper filter.
InStr(Join(Parameters!ProvinceID.Value,”,”),0)
Shouldn't that 0 be "0"
Try:
=IIf(
InStr(Join(Parameters!ProvinceID.Value, ", "), "0") > 0
,True
,IIf(
InStr(Join(Parameters!ProvinceID.Value, ", "), Fields!ProvinceID.Value) > 0,
,True
,False
)
)
InStr will return an integer value of the position where the string searched for starts (if found). Therefore your boolean tests (1st argument of the IIf() function) need to determine if a number equal to or greater than 1 has been returned.
As you are searching for a string, the 0 being searched for in the string must be coded as "0".
If Fields!ProvinceID.Value returns an integer, then it too must be converted to a string using the CStr() function like so:
=IIf(
InStr(Join(Parameters!ProvinceID.Value, ", "), "0") > 0
,True
,IIf(
InStr(Join(Parameters!ProvinceID.Value, ", "), CStr(Fields!ProvinceID.Value)) > 0,
,True
,False
)
)
What are you comparing to? Usually the IIF needs something like =IIF(Fields!ListBox1.Value = "value", "option1", "option2")
=IIF(Fields!Eyes.Value = "Green", "Green", "Other Colour")
Related
I'm trying to achieve string truncate with "& more..." when string is truncated. I have this in picture:
Exact code minus text, in image:
func formatString() -> String {
let combinedLength = 30
// This array will never be empty
let strings = ["Update my profile", "Delete me", "Approve these letters"]
// In most cases, during a loop (no order of strings)
//let strings = ["Update", "Delete", "Another long word"]
let rangeNum = strings.count > 1 ? 2 : 1
let firstN = strings[0..<rangeNum]
// A sum of first 2 or 1
let actualLength = firstN.compactMap { $0.count }.reduce(0, +)
switch actualLength {
case let x where x <= combinedLength:
// It's safe to display all
return strings.map{String($0)}.joined(separator: ", ")
default:
if rangeNum == 2 {
if actualLength <= combinedLength {
return strings.first! + ", " + strings[1] + ", & \(strings.count - 2) more..."
}
return strings.first! + ", & \(strings.count - 1) more..."
}
// There has to be at least one item in the array.
return strings.first!
}
}
While truncateMode looks like a match, it's missing the , & n more... where n is the remainder.
My code may not be perfect but was wondering how to refactor. I feel there's a bug in there somewhere. I've not taken into consideration for larger screens: iPad where I would want to display more comma-separated values, I only look for the max 2 then display "& n more" depending on the size of the array.
Is there a hidden modifier for this? I'm using XCode 13.4.1, targeting both iPhone and iPad.
Edit:
The title is incorrect. I want to convert an array of strings into a comma-separated value string that's truncated using the function I have.
Asking for some help here, im trying to convert text to time in duration format on Google Sheets, i´ve used some basic fuctions to to breakdown text (with delimiters as d (days) h (hour) m(minute) and s(second) into values that were then baked into a time function, however for outputs over 24 hours I was unable to get it to format properly i.e. in the image below 375 hrs should show 375:00:00 or [H]:mm:ss
Any ideas here?
Sharing the doc
https://docs.google.com/spreadsheets/d/1YWHM5tPaLOulHMbfdR8CZJsER7LBceWLQrm9f8JcV9c/edit#gid=0
Try, in J12
=(G12+H12/60+I12/60/60)/24
then apply duration format
try:
=FLATTEN(INDEX(QUERY(, "select "&TEXTJOIN(",", 1,
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B7:B27,
"d", "*86400"), "h", "*3600"), "m", "*60"), "s", "*1"), " ", "+")))/86400, 2))
Use regexextract(), like this:
=arrayformula(
iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" &
iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" &
iferror(regexextract(B7:B, "(\d+)\s*s"), 0)
)
The formula gives text strings. To get numeric durations, use value(), like this:
=arrayformula(
iferror( 1 /
value(
iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" &
iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" &
iferror(regexextract(B7:B, "(\d+)\s*s"), 0)
)
^ -1 )
)
Format the result column as Format > Number > Duration.
In the event there are many components in the text string you are converting, it may be beneficial to use just one regextextract(), which is possible using the recently introduced lambda functions:
=arrayformula(
map(
B7:B,
lambda(
duration,
if(
len(duration),
join(
":",
iferror(
regexextract(
duration,
{ "(\d+)\s*h"; "(\d+)\s*m"; "(\d+)\s*s" }
),
0
)
),
iferror(1/0)
)
)
)
)
See this answer for an explanation of how date and time values work in spreadsheets.
When doing so I get the Error Code:
Cannot assign value of type '(String, String)' to type 'String?'
As you can see below, I have already converted the Numbers to String values which didn't help.
Ultimately I want to have an UI Label which displays a value + String depending on a switch function.
The Value is going to switch Units and the UI Label should say ( 256 Days or 3.5 hours and for the last example not 0.14 days)
Assigning the Units when printing inti the XCode Console is easy. What I would need is to copy the Console Output ( Target Output) and then paste it into a UI Label, if the other method doesnt work.
Here the Code :
switch Differenz {
case 1...9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 : print (Differenzstring,"Years")
case 0.0027...0.99 : print ( Differenz*365, "Days ")
case 0.000114...0.00269 : print (Differenz * 365*24,"Hours")
case 0.0000019...0.0001139 : print (Differenz * 365 * 24 * 60, "Minutes" )
case 0.000000000001 ... 0.00000189 : print (Differenz * 365 * 24 * 60 * 60,"Seconds")
case 0...0: print ( "Time (almost) stops")
default : print ( "Calculation failed" )
}
// Units not inegrated yet, Result will therefore be in Years perfect would be the Cosnole Output, provided by the Switch Statement also being pasted into "Output Label"
Output.text = String ( Differenz )
}
could you try this out?
var usedTimeLabel = "seconds" //reassign this value when doing switch
Output.text = "\(Differenz) \(usedTimeLabel)"
I have a function that categorizes calls a user has made into 3 categories using this calculation:
IF 0 <= DATEDIFF('dayofyear', [SubmittedDateTime], [CALLDATE])
AND DATEDIFF('dayofyear', [SubmittedDateTime], [CALLDATE]) <= 7
THEN "Week After"
ELSEIF -7 <= DATEDIFF('dayofyear', [SubmittedDateTime], [CALLDATE])
AND DATEDIFF('dayofyear', [SubmittedDateTime], [CALLDATE]) < 0
THEN "Week Before"
ELSE "Not within a week"
END
I was wondering if it's possible to count the number of occurrences of a particular outcome of the function on a per user basis in order to then categorize each user based off of the number of occurrences. I'm attempting to use this calculation to do so:
IF { FIXED [SUBID]: COUNT([DateDiff Calc] = 'Week After')} = 1
THEN "1 Conference User"
ELSEIF { FIXED [SUBID]: COUNT([DateDiff Calc] = 'Week After') } > 1
THEN "Multiple Conference User"
ELSE "0 Conference User"
END
but the COUNT function I'm using is not working properly it seems. It seems that the COUNT function is also counting occurrences of both "Week Before" and "Not within a week" from the first function.
I think the problem is the measure part of your LOD expression :
COUNT([DateDiff Calc] = 'Week After')
This will just give you count of both times: when your conditions is met and when its not met. [DateDiff Calc] = 'Week After' will return true or false, both will be counted as +1 in the count function.
You could try something like:
IF { FIXED [SUBID]: SUM(IF[DateDiff Calc] = 'Week After' THEN 1 ELSE 0 END)} = 1
THEN "1 Conference User"
...
I'm trying to use ThinkingSphinx to return records that have a start date within a range OR an end date within the same range, basically any record that starts or ends within this range.
To do this, I am using a computed attribute and sphinx_select as per the documentation in combination with what this post suggests for date ranges, as follows (assume there are two records, record_a starts outside the range, but ends within the range and record_b starts and ends within the range):
with_display = "*, IF(start_at >= #{range_start.to_i}, 1, 0) + " +
"IF(start_at <= #{range_end.to_i}, 1, 0) + " +
"IF(end_at >= #{range_start.to_i}, 10, 0) + " +
"IF(end_at <= #{range_end.to_i}, 10, 0) AS display"
{
sphinx_select: with_display,
with: {'display' => [2, 20, 22]},
}
=> [record_b]
However, if I only use the start_at conditions, I get one record, and if I use only the end_at conditions, it returns both records.
with_display = "*, IF(start_at >= #{range_start.to_i}, 1, 0) + " +
"IF(start_at <= #{range_end.to_i}, 1, 0) AS display"
=> [record_b]
with_display = "*, IF(end_at >= #{range_start.to_i}, 10, 0) + " +
"IF(end_at <= #{range_end.to_i}, 10, 0) AS display"
=> [record_a, record_b]
If I'm understanding this correctly, having all four conditions, should result in both record_a and record_b being returned, since record_a should have a display value of 20, while record_b should have a display value of 22.
Am I missing something?
I just realized my math was wrong, given the cases I want to handle:
record_a will have a display of 21
record_b will have a display of 22
What I needed to do was change my array to:
{
sphinx_select: with_display,
with: {'display' => [12, 21, 22]},
}
in order the handle the cases of records that end within the range (21), records that start within range (12), and records than start and end within the range (22)