How to get a constant string value for a new field in Google data studio? - formula

I am using Google Data Studio and I have a report that draws data from a source with x fields.
When editing the data source I create a new field with the following formula:
CASE
WHEN (field_1 IS NOT NULL OR field_1 IS NULL) THEN "foo"
ELSE "bar"
END
that should return "foo" for every row of that data source since the statement is always true.
Initially I tried something like foo or "foo"or
CASE
WHEN (True) THEN "foo"
END
for the formula but I got the error for invalid formula.
My issue is that it returns "bar" for every row.
What am I doing wrong?
Thanks

How about using CONCAT('foo','') as the formula?

Related

How can I dynamically change the where conditions of a for each loop?

I have a table of records that has two logical flags, holdn and holdl. I want to loop through this table with 3 different criteria.
Either flag is TRUE - We want to see everything that is on hold
Flag holdl is TRUE - We only want see items that are on hold for this one reason
Flag holdn is TRUE - We only want to see items that are on hold for this other reason.
I cannot figure out how to dynamically change the for each loop based on this. What I have tried so far is to set the value of a variable based on these conditions and then use the content of the variable as one of the where parameters. This does not work as Progress complains that there is a data mismatch. The variable is a string, the flags are logical, so that does make sense. See sample code below. This is a snippet of the actual code with the the table name changed. The which-hold, order-from, etc variables are defined and set in a different module which calls this one.
DEFINE VARIABLE which-hold# AS CHARACTER FORMAT "x(30)" NO-UNDO.
CASE which-hold:
WHEN "B" THEN which-hold# = "(widget.holdn or widget.holdl)".
WHEN "L" THEN which-hold# = "widget.holdl".
WHEN "N" THEN which-hold# = "widget.holdn".
END CASE.
for each widget where which-hold# and
widget.order-no >= order-from and widget.order-no <= order-thru and
widget.line-no >= line-from and widget.line-no <= line-thru and
widget.joint-no >= joint-from and widget.joint-no <= joint-thru
no-lock:
A bunch of code to make a nice report with the retrieved records...
end.
Self taught Progress programmer here, who has inherited a huge, poorly documented application. Please be gentle.
If you would prefer not to deal with handles a semi-dynamic approach is also possible:
define variable i as integer no-undo.
define query q for customer.
do while true:
update i.
case i:
when 0 then quit.
when 1 then open query q for each customer no-lock where custNum >= 1000.
when 2 then open query q for each customer no-lock where state = "nh".
otherwise open query q for each customer no-lock where name begins "u".
end.
do while true with frame a:
get next q.
if not available customer then leave.
display custNum name state with frame a 10 down.
down with frame a.
end.
close query q.
end.
What you want is actually a dynamic query. I'll get to it at the end, but first I'd like to explain why you won't be able to try and substitute the field name in the which-hold# variable: because the query is evaluated at compile time. And this is what it reads (supposing which-hold# has a value of widget.holdn
FOR EACH widget where "widget-holdn" (...)
And that does not evaluate to TRUE or FALSE. So what, you ask? Well, that is the key here. Every condition needs to evaluate to true or false, so you'd be more in luck if you try
for each widget where (if widget-hold# = 'widget.holdn' then widget.holdn = true else TRUE) (...)
Again, notice the condition will exist if widget-hold# has the value I want, otherwise it doesn't filter on this at all.
So you can just code the way I showed (for each of the conditions you have) and it should work fine.
BUT let me suggest a dynamic query instead.
You need to have:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(BUFFER widget:HANDLE).
hQuery:QUERY-PREPARE('<THIS IS THE CORE>').
hQuery:QUERY-OPEN().
DO WHILE hQuery:GET-NEXT():
A bunch of code to make a nice report with the retrieved records...
END.
So in the core you have a string that corresponds to your for each the way you want it to look. So it should be for example (store this in a variable, or assemble it inside the query prepare, it doesn't matter):
'FOR EACH widget NO-LOCK WHERE ' +
(if which-hold = 'B' then 'widget.holdn = true and widget.holdl = true'
else if which-hold = 'L' then 'widget-holdl = true'
else /* N */ 'widget-holdn = true').
Remember I said your query is evaluated at compile time? Well, just so you know, dynamic queries on the other end are evaluated at run time, so be prepared for errors to pop up only when you run. Another thing I should mention is dynamic queries are slower than static ones, so please evaluate and choose your poison :)
This should be what you need. Please let me know if it's helpful or any questions remain.

Handling dimension with empty names in icCube

How can I get icCube to handle a dimension where there are empty values in the backing table? I get the following error message from icCube when I try to scan our tables:
Data table 'public.accounting_area_dim', line '22' : The member key:'22' has no name (nameColumn:area) (level:[Area].[Area].[Area])
This is absolutely correct, there are empty strings in the dimension table - I'd like to treat it as "Unknown" or something similar, is this possible in icCube?
You can transform the empty string into something else within the table definition as following:
Hope that helps.

SQLite: result of mathematical operation always is a text

I created the following table:
CREATE TABLE test (a INT,b INT);
After I inserted some data:
INSERT INTO test VALUES(1,2);
When I execute this SELECT:
SELECT cast(b as real) as x, a * b as y FROM teste
the fields "x" and "y" return with datatype TEXT. I'm using Delphi and SQLiteStudio 2.1.5, and both return the same datatype.
I need that field x being real and y being int.
Someone could help me?
Sqlite does not have column data type. It is just text. Based on your expression, it will try to do the conversion for you. For your math expression, you need to do a cast to give it is a hint to delphi to create your desired column type.
For me it's strange that in Sqlite, column types are "recommendations". But analyzing this I changed my program. I created the fields manually with correct type. So the program start to work.
The problem is when you open a query and the Delphi create the columns automatically. In this case, the columns with cast or with mathematical operation are created like text field.

Using UTCTime with SQLite in Yesod

While using a UTCTime field in my model in Yesod, I get the following error:
PersistMarshalError "field timestamp: Expected UTCTime, received PersistText \"09:18:07\""
I am using SQLite to store my database. My model looks as follows:
Myobject
timestamp UTCTime default=CURRENT_TIME
otherfield Text
Note that this error occurs both with and without the default value.
I am selecting the list of Myobject-entities as follows:
myobjects <- selectList [] [Desc MyobjectTimestamp]
Using MyobjectOtherfield instead of MyobjectTimestamp does not help either, which makes sense since all data is fetched and therefore marshaled anyway.
A similar question has been asked here, but the answer did not help me.
How can I use UTCTime in Yesod while using SQLite?
Edit:
The PersistText \"09:18:07\" that is mentioned in the error is the value the field defaulted to.
You stored a Text value "09:18:07", while it expected a UTCTime value. Did you insert values by hand?
getCurrentTime from Data.Time returns a value of type IO UTCTime, so you can either use putStr getCurrentTime in GHCI to get a valid representation, or use now <- liftIO getCurrentTime in your function.
EDIT:
Because getCurrentTime returns a timestamp like: 2013-10-25 10:16:32.1627238 UTC, inserting a value like that in your database should resolve the error.

Can someone please explain what the following code does?

I'm currently working on a project that was written in classic asp. I've used this language some before but I'm rusty with it.
In that code I see the following function call:
Result = SwapOEMPart(sItem)
When I look at SwapOEMPart I see this:
function SwapOEMPart(oemPart)
// Do a bunch of stuff
oemPart = objRS("CCIPartNo") <-- this is the result of the stuff
end function
What does that do? Does it fill Result with the value of oemPart? Does it change the value of sItem (similar to a pass by reference)? Or perhaps it is something entirely different.
I'm familiar with returning data from asp functions by setting the function name equal to the value you want to return, but in this instance they are changing the value of the parameter they pass in and then just ending the function.
Based on the code you have provided, I'm going to assume objRS is an adodb.recordset, if that is the case, CCIPartNo is a column in the recorset, all your code is doing is writing the value of that column into the eomPart variable - eomPart isnt referenced as byref in the function declaration but this is assumed as default if you're in vbscript (not .net) so **it's almost as if the value of the column is being passed back into eomPart & because eomPart is a REFERENCE to the sItem value in your example, the actual value of sItem would change.
http://msdn.microsoft.com/en-us/library/ee478101%28VS.84%29.aspx

Resources