I am trying to do a conditional statement that displays the inventory items that contain w3 in the ID. I then need to use the same GI and create another column that displays the inventory item that contains FG in the INV ID.
I have tried this expression without any success:
=IIf( 'w3' In [left(inventoryCD,2)], inventoryCD, null )
=IIf( 'FG' In [left(inventoryCD,2)], inventoryCD, null )
Try to use InStr instead of In operator. Here is example above:
=IIf(InStr(Left(InventoryCD,2),'w3')>0, InventoryCD, null )
=IIf(InStr(Left(InventoryCD,2),'FG')>0, InventoryCD, null )
Related
Given the following Derived column Expression
case(Rolling =='A'||Rolling == 'B'||Rolling == 'C'|| Rolling =="S"
, "
, case(Alpha== 'EE'
, toString(toDate(Manu_Date, 'yyyy-MM-dd'))
, case(Alpha=='CW', Del_Date,"))
)
2 questions
Is there a Better way to write this code?
What is this code trying to do ?
I am trying to understand what they are trying to achieve with this expression?
In the given expression, after Rolling=="S", it is not double Quotes ". It should be two single quotes''
Similarly, after Del_date, also it should be two single Quotes.
case(Rolling =='A'||Rolling == 'B'||Rolling == 'C'|| Rolling =="S", '',
case(Alpha== 'EE', toString(toDate(Manu_Date, 'yyyy-MM-dd')),
case(Alpha=='CW', Del_Date,'' )))
What is this code trying to do ?
Syntax for case statement is
case(condition,true_expression,false_expression)
Initially, this expression checks if Rolling is 'A' or 'B' or 'C' or 'S' and then assign the value as '' (empty string) for the derived column.
When the above condition is false, then checks if Alpha is 'EE' and assign the value of Manu_Date in string format.
When the second condition also fails, it checks if Alpha='CW' and assign the value of Del_Date column.
When all the above conditions are not met, '' (empty string) is assigned. This will be the default value.
I repro'd this with sample input.
img1: input data
In derived column transformation, new column is added, and the expression is given as in below script.
case(Rolling =='A'||Rolling == 'B'||Rolling == 'C'|| Rolling =="S", '',
case(Alpha== 'EE', toString(toDate(Manu_Date, 'yyyy-MM-dd')),
case(Alpha=='CW', Del_Date,'' )))
img2: Derived column transformation output
Is there a Better way to write this code?
Since the order of condition is important to assign the values to the new column, case statement is better way to do.
But, instead of using nested case statements, we can use single case statement to achieve the same.
Syntax:
case( condition_1, expression_1, condition_2, expression_2,.......... condition_n,expression_n,default_expression).
Null will be the default value, when the default expression is omitted.
Modified expression
case(Rolling =='A'||Rolling == 'B'||Rolling == 'C'|| Rolling =="S", '',
Alpha== 'EE', toString(toDate(Manu_Date, 'yyyy-MM-dd')),
Alpha=='CW', Del_Date,'' )
img 3: Results of both case statements
Both the expressions are added in the derived column transformation and results are same in both cases.
I Want to customise automatically in Excel a Reference number according to the content of the line it is representing.
I have a table for test procedure that looks like this :
Ref
Action
Check
A 001
Name of the Action to perform
Empty if it is an Action
C 001
Empty if it is a Check
Name of the Check to perform
C 002
Empty if it is a Check
Name of the Check to perform
C 003
Empty if it is a Check
Name of the Check to perform
A 002
Name of the Action to perform
Empty if it is an Action
The logic would be the following:
To iterate separately references starting with A and the ones starting with C depending on the type of procedure, that is to say whether the name of the procedure is in Action Column or Check Column.
I would like to implement an algorithm like this, or a formula that does the same thing :
For line in TABLE1 :
if ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Action = Ref_Action + 1
Ref_Code = "A" + Ref_Action
elif ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Check = Ref_Check + 1
Ref_Code = "C"+ Ref_Check
else raise error : "a procedure shall be either an action or a Procedure"
TABLE1[line,Ref] = Ref_Code
(It is not a code language, just my way of representing the algorithm, I hope it is readable.)
Unfortunately, I have no experience in VBA and I couldn't find a way to write an appropriate formula. Or maybe there is another way ?
Thank you,
Gautier
I was using the SELECT method in a function. I tried to Select all the rows where "First_Name," a column, is equal to "FirstName," a variable. However, it gives me an error saying that "FirstName" is not a column. I have no idea how to fix this issue. I have copy-pasted the SELECT statement below.
c.execute('SELECT * FROM AccountLists WHERE First_Name = FirstName AND Last_Name = LastName')
You need use ? notation, like this:
c.execute('SELECT * FROM AccountLists WHERE First_Name=? AND Last_Name=?', (FirstName, LastName))
The ? is a placeholder that you use wherever you want to use a value and then provide a tuple of values as the second argument to the cursor’s execute() method.
I am having a hard time when I try to run the script below. Error messsage:
Order by clause not valid in views and inline functions
insert into cc.s
(
id,
encid,
a_name,
a_des,
a_type,
a_value,
d_create
)
select
id,
encid,
'days_charge',
'Days 43',
'int',
(
select
datediff(day,t_dis,a.ts_it)
from
cc.enoun
where
encid <> a.encid
and id=a.pe_id
and a_source='tEst'
and a.ts_admit > t_dis
order by
tdischarge desc limit 1
) as attr_value,
getdate()
from
cc.s a
GO
In your script, you're trying to use a SELECT statement to get the a_value. Your problem here is that this select statement is your inline function. Since an inline function can't have an ORDER BY clause, you simply have to remove it.
insert into cc.s(id, encid, a_name, a_des, a_type, a_value, d_create)
select id, encid,'days_charge','Days 43','int',
(select datediff(day,t_dis,a.ts_it) from cc.enoun where encid<>a.encid and id=a.pe_id and a_source='tEst' and a.ts_admit>t_dis)
as attr_value,
getdate()
from cc.s a
GO
Also make sure that your inline statement returns only 1 value. Since you were trying to use an ORDER BY clause, that may mean that it returns multiple results.
I understand that InterpolateRGBColors function is returning a color by position of value between 0 and 1... So its seems to be doable only with percentages, not numbers...
Is there a way to have the same functionality, but based on the min and max values returned in a set ?
What I want is to attribute colors to my measure but in a range of min([Measures].[NbSejours]) to max([Measures].[NbSejours]) ( not 0 to 1)...
WITH
MEMBER [Measures].[color] AS
InterpolateRGBColors(
[Measures].[NbSejours]
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
SELECT
{
{[Measures].[NbSejours]}
,[Measures].[color]
} ON COLUMNS
,{
NonEmpty
(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
)
} ON ROWS
FROM
(
SELECT
{{[Periode].[Periode].[All-M].&[2013]}} ON 0
FROM [Cube]
)
CELL PROPERTIES
STYLE
,CLASSNAME
,VALUE
,FORMATTED_VALUE;
Is there a way to do that ?
InterpolateRGBColors expect a numerical between 0 and 1 for interpolation. So we need to scale our measure to ensure we get the right colors.
There is an example in our live demo , here.
What we need is to scale [Measures].[NbSejours] between 0,1. There are two no documented function in icCube DistributionFlat & DistributionRank.
A non efficient version
WITH
SET [AxisX] AS NonEmpty([Etablissement].Etablissement].Etablissement].ALLMEMBERS,[Measures].[NbSejours])
FUNCTION distr(x_) as DistributionFlat( [AxisX], [Measures].[NbSejours], x_ )
MEMBER [Measures].[color] AS
InterpolateRGBColors(
distr([Measures].[NbSejours])
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
....
Once I got a bit of time I'll write a version using Vectors (here and here) that is more performant as in the example above we calculate every time the values for the set.
Hope it helps
I don'r know icCube so the following might not work, even though I have used standard functions. As #George commented you can use the standard RANK function to find each members relative position.
You will need to feed that value into the definition of [Measures].[color]...
WITH
SET [estMembersOrdered] AS
ORDER(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
,BDESC
)
MEMBER [Measures].[rnkEtablissement] AS
RANK(
[Etablissement].[Etablissement].CURRENTMEMBER
, [estMembersOrdered]
)
MEMBER [Measures].[color] AS
InterpolateRGBColors(
[Measures].[NbSejours]
,rgb(176,224,230)
,rgb(135,206,235)
,rgb(0,191,255)
,rgb(100,149,237)
,rgb(0,0,255)
,rgb(0,0,139)
,rgb(25,25,112)
), BACK_COLOR=currentCellValue()
SELECT
{
{[Measures].[NbSejours]}
,[Measures].[color]
,[Measures].[rnkEtablissement]
} ON COLUMNS
,{
NonEmpty
(
[Etablissement].[Etablissement].[Etablissement].ALLMEMBERS
,[Measures].[NbSejours]
)
} ON ROWS
FROM
(
SELECT
{{[Periode].[Periode].[All-M].&[2013]}} ON 0
FROM [Cube]
)
CELL PROPERTIES
STYLE
,CLASSNAME
,VALUE
,FORMATTED_VALUE;