Misplaced parenthesis in expression - visual-studio-2010

Another pair of eyes to look at this would be great. I get one of two error messages the more I mess with this. Either it want's another parenthesis or that it's not a proper use of True/False. Im just getting a little frustrated looking at it. Any help would be much appreciated. It's been a long day.
=IIF((Sum(Fields!January.Value, "CDataSet")- Code.DivideBy(Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")) < 0
and (Sum(Fields!January.Value, "CDataSet")- Code.DivideBy(Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")))> Sum(Fields!Variance.Value, "CDataSet")),"Red",
IIF((Sum(Fields!January.Value,"CDataSet")- Code.DivideBy(Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2"))) > 0
and (Sum(Fields!January.Value, "CDataSet")- Code.DivideBy(Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2"))) > Sum(Fields!Variance.Value, "CDataSet")), "LimeGreen","Transparent")

When I indent the code to the levels of parentheses, I get:
=IIF(
(
Sum(Fields!January.Value, "CDataSet") - Code.DivideBy(
Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")
) < 0
and (
Sum(Fields!January.Value, "CDataSet") - Code.DivideBy(
Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")
)
) > Sum(Fields!ThresholdAging.Value, "CDataSet")
),
"Red",
IIF(
(
Sum(Fields!January.Value,"CDataSet") - Code.DivideBy(
Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")
)
) > 0
and (
Sum(Fields!January.Value, "CDataSet") - Code.DivideBy(
Fields!M191.Value, Sum(Fields!Totals.Value, "DataSet2")
)
) > Sum(Fields!ThresholdAging.Value, "CDataSet")
),
"LimeGreen",
"Transparent"
)
Conclusion: The inner IIF has only one parameter, and the outer IIF has five. I think that you meant to put the two last strings in the inner IIF:
...
) > Sum(Fields!ThresholdAging.Value, "CDataSet"),
"LimeGreen",
"Transparent"
)
)

Related

Performance enhancement in DAX query

I have Power BI DAX query used in a measure. It takes longer time to execute. Can anyone please help me with this?
MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SWITCH (
TRUE (),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "1 - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "2 - NON - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1
)
Performance Result on DAX Studio:
Can you please try this code, see if It solves your problem. I tried to write it without contains() function.
MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SUMX (
FACT_CONSOL_BALANCE_OL,
VAR Balance =
SWITCH (
RELATED ( DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)] ),
"1 - CURRENT ASSETS", FACT_CONSOL_BALANCE_OL[BALANCE],
"2 - NON - CURRENT ASSETS", FACT_CONSOL_BALANCE_OL[BALANCE],
FACT_CONSOL_BALANCE_OL[BALANCE] * -1
)
RETURN
Balance
)

How to fix the 'expected right parenthesis' happening in the 4th line : tau0*(t[j+1]-t[j]) in winbugs

I need to estimate four parameters using winbugs: tau[i], mu1[i],mu2[i]and tau0[i].
When I click check the model, it shows expected right parenthesis between tau0* and (t[j+1]-t[j]) in the 4th line.
When I delete the (t[j+1]-t[j]), it shows the same expected right parenthesis between c and <-(1-step( tau[i]-t[j]))
model
{
#likelihood
for(i in 1:n){
for(j in 1:m){
x[i,j]~ dnorm( mu[i,j], tau0*(t[j+1]-t[j]))
mu[i,j]<- mu1*(t[j+1]-t[j])*a+mu1*(tau[i]-t[j])*b+mu2*(t[j+1]-tau[i])*b+mu2*(t[j+1]-t[j])*c
sigma <-1/sqrt(tau0)
a<-step( tau[i]-t[ j+1] )
b<-(step(tau[i]- t[j])-(step(tau[i]- t[j+1]))
c<-(1-step( tau[i]-t[j]))
}
#prior
tau[i]~dnorm(mutau,tautau)
mutau~dorm(0, 0.001)
tautau~dgamma(0.01, 0.01)
sigmatau<-1/sqrt(tautau)
mu1[i]~dnorm(mumu1, tau1)
mumu1~dorm(0, 0.001)
tau1~dgamma(0.01,0.01)
sigmatau1<-1/sqrt(tau1)
mu2[i]~dnorm(mumu2, tau2)
mumu2~dorm(0, 0.001)
tau2~dgamma(0.01,0.01)
sigmatau2<-1/sqrt(tau2)
tau0[i]~dgamma(alpha,beta)
sigmatau0<-1/tau0
}
}
DATA
list(n=5, m=16, mutau=0, tautau=1, mumu1=0, tau1=1, mumu2=0, tau2=1, alpha=0.01, beta=0.01 )
I expected the right model syntax
b<-(step(tau[i]- t[j])-(step(tau[i]- t[j+1]))
(
step(
tau[i]- t[j]
)
-
(
step(
tau[i]- t[j+1]
)
)
4 brackets opening, 3 brackets closing.
First bracket is not closed.

Netlogo How to avoid NOBODY Runtime error?

How can I avoid NOBODY Runtime error? The following is sample code. This is a code that can be used for zero division error avoidance. Therefore, I know that it can not be used to avoid NOBODY error. But I can not find any other way. The following is a Runtime error message-> "IFELSE-VALUE expected input to be a TRUE / FALSE but got NOBODY instead." I appreciate your advice.
set top ifelse-value (nobody)
[ 0 ][ top ]
set ts turtles with [speed = 0 and not right-end]
set top max-one-of turtles [who]
set topx [xcor] of top ; A NOBODY error appears in "of" of this code
set L count ts with [xcor > topx]
The input of ifelse-value needs to be a reporter the returns either true or false (full details here. So, if you use nobody as the input, Netlogo does not evaluate whether or not the input is nobody or not, it just reads nobody- in other words your input is not returning either true or false.
For input, then, you need to instead use a boolean variable (one that is either true or false), a to-report that returns true or false, an expression that Netlogo can evaluate, etc. Consider the following examples:
to go
let x true
set top ifelse-value ( x )
["x is true"]
["x is NOT true"]
print ( word "Example 1: " top )
set top ifelse-value ( this-is-true )
["Reporter returned true"]
["Reporter did not return true"]
print ( word "Example 2: " top )
set x nobody
set top ifelse-value ( x = nobody )
["x IS nobody"]
["Is NOT nobody"]
print ( word "Example 3: " top )
set x 0
set top ifelse-value ( x = nobody )
["x IS nobody"]
["x Is NOT nobody"]
print ( word "Example 4: " top )
set top ifelse-value ( nobody = nobody )
["nobody = nobody"]
["nobody != nobody"]
print ( word "Example 5: " top )
end
to-report this-is-true
report true
end

How to make the agent pick the highest value between two values?

guys. I created this procedure in NetLogo for my agents (farmers):
to calculate-deforestation
ask farmers [
set net-family-labor ( family-labor - ( ag-size * cell-labor-ag-keep ) )
set net-family-money ( family-money - ( ag-size * cell-cost-ag-keep ) )
ifelse net-family-labor < 0 or net-family-money < 0
[ set n-aband-cell-labor ( family-labor / cell-labor-ag-keep )
set n-aband-cell-money ( family-money / cell-cost-ag-keep )
set n-aband with-max [ n-aband-cell-labor n-aband-cell-money ]
]
[ set n-def-cell-labor ( net-family-labor / cell-labor-deforest )
set n-def-cell-money ( net-family-money / cell-cost-deforest )
set n-def with-min [ n-def-cell-labor n-def-cell-money ]
]
]
end
For the "n-aband", I would like to get the max value between "n-aband-cell-labor" and "n-aband-cell-money" (either one or the other; the same goes for "n-def"). I know a limited number of NetLogo primitives but the ones I was able to find do not work for my case, for instance, "with-max", "max-n-of", "max-one-of". I am sure there must be one that would work but I am having trouble finding it in the NetLogo dictionary. I wonder if anyone could suggest me one that could work for my case. Thank you in advance.
If you want to get the max value of a list, simply use max. So,
set n-aband max (list n-aband-cell-labor n-aband-cell-money )
will set n-aband to the highest of the two values.

left join do not show all records

In following code left join do not show all the records from left !!!
select *,CASE WHEN (ResDEBIT> ResCREDIT) THEN (ResDEBIT) when (ResCREDIT> ResDEBIT)then (ResCREDIT) else 0 END AS Mande,CASE WHEN (ResDEBIT> ResCREDIT) THEN ('debit') when (ResCREDIT> ResDEBIT)then ('credit') ELSE ('ziro') END AS Status from(SELECT Sales.CustomerInfo.CustomerInfoID,FullTitle=(cast(Sales.CustomerInfo.AccountFK as nvarchar)+' - '+Sales.CustomerInfo.FullName), Sales.CustomerInfo.TopicFK, Sales.CustomerInfo.AccountFK,Sales.CustomerInfo.CompanyRegNo,Sales.CustomerInfo.PersonTypeFK,Sales.CustomerInfo.BankAccountDetail,Sales.CustomerInfo.BankAccountNo, Sales.CustomerInfo.AccountNo, Sales.CustomerInfo.FullName,
Sales.CustomerInfo.Birthdate, Sales.CustomerInfo.TitleFK, Sales.CustomerInfo.RegistrationDate, Sales.CustomerInfo.CustomerPhotoFK, Sales.CustomerInfo.SocialNo,
Sales.CustomerInfo.WebPage, Sales.CustomerInfo.JobFK, Sales.CustomerInfo.MaxDebitLimit, Sales.CustomerInfo.MaxChequeCredit,
Sales.CustomerInfo.PreferedPaymentMethodFK, Sales.CustomerInfo.FirstBalanceKind, Sales.CustomerInfo.FirstBalance, Sales.CustomerInfo.Debit,
Sales.CustomerInfo.Credit, Sales.CustomerInfo.Note, Sales.CustomerInfo.FinancialPeriodFK, Sales.CustomerInfo.CompanyInfoFK,
isnull(SUM(Accounting.DocumentDetail.Debit),0) AS Debit1, isnull(SUM(Accounting.DocumentDetail.Credit),0) AS Credit1, (CASE WHEN (isnull(SUM(Accounting.DocumentDetail.Credit),0)
- isnull(SUM(Accounting.DocumentDetail.Debit),0)) < 0 THEN (isnull(SUM(Accounting.DocumentDetail.Debit),0) - isnull(SUM(Accounting.DocumentDetail.Credit),0)) ELSE 0 END) AS ResDEBIT,
(CASE WHEN (isnull(SUM(Accounting.DocumentDetail.Credit),0) - isnull(SUM(Accounting.DocumentDetail.Debit),0)) > 0 THEN (isnull(SUM(Accounting.DocumentDetail.Credit),0)
- isnull(SUM(Accounting.DocumentDetail.Debit),0)) ELSE 0 END) AS ResCREDIT,Sales.CustomerInfo.BlackListed, Sales.CustomerInfo.IsActive
FROM Sales.CustomerInfo left JOIN
Accounting.DocumentDetail ON Sales.CustomerInfo.AccountFK = Accounting.DocumentDetail.TopicFK
GROUP BY Sales.CustomerInfo.CustomerInfoID, Sales.CustomerInfo.TopicFK, Sales.CustomerInfo.AccountFK, Sales.CustomerInfo.AccountNo,
Sales.CustomerInfo.FullName, Sales.CustomerInfo.Birthdate, Sales.CustomerInfo.TitleFK,Sales.CustomerInfo.CompanyRegNo,Sales.CustomerInfo.PersonTypeFK,Sales.CustomerInfo.BankAccountDetail,Sales.CustomerInfo.BankAccountNo, Sales.CustomerInfo.RegistrationDate,
Sales.CustomerInfo.CustomerPhotoFK, Sales.CustomerInfo.SocialNo, Sales.CustomerInfo.WebPage, Sales.CustomerInfo.JobFK, Sales.CustomerInfo.MaxDebitLimit,
Sales.CustomerInfo.MaxChequeCredit, Sales.CustomerInfo.PreferedPaymentMethodFK, Sales.CustomerInfo.FirstBalanceKind, Sales.CustomerInfo.FirstBalance,
Sales.CustomerInfo.Debit, Sales.CustomerInfo.Credit, Sales.CustomerInfo.Note, Sales.CustomerInfo.FinancialPeriodFK, Sales.CustomerInfo.CompanyInfoFK,
Sales.CustomerInfo.BlackListed, Sales.CustomerInfo.IsActive) CustomerInfo
check how many distinct record exists for your group by columns
Select distinct
Sales.CustomerInfo.CustomerInfoID
,Sales.CustomerInfo.TopicFK
,Sales.CustomerInfo.AccountFK
,Sales.CustomerInfo.AccountNo
,Sales.CustomerInfo.FullName
,Sales.CustomerInfo.Birthdate
,Sales.CustomerInfo.TitleFK
,Sales.CustomerInfo.CompanyRegNo
,Sales.CustomerInfo.PersonTypeFK
,Sales.CustomerInfo.BankAccountDetail
,Sales.CustomerInfo.BankAccountNo
,Sales.CustomerInfo.RegistrationDate
,Sales.CustomerInfo.CustomerPhotoFK
,Sales.CustomerInfo.SocialNo
,Sales.CustomerInfo.WebPage
,Sales.CustomerInfo.JobFK
,Sales.CustomerInfo.MaxDebitLimit
,Sales.CustomerInfo.MaxChequeCredit
,Sales.CustomerInfo.PreferedPaymentMethodFK
,Sales.CustomerInfo.FirstBalanceKind
,Sales.CustomerInfo.FirstBalance
,Sales.CustomerInfo.Debit
,Sales.CustomerInfo.Credit
,Sales.CustomerInfo.Note
,Sales.CustomerInfo.FinancialPeriodFK
,Sales.CustomerInfo.CompanyInfoFK
,Sales.CustomerInfo.BlackListed
,Sales.CustomerInfo.IsActive
from Sales.CustomerInfo
the number of return records for your above query will be same...To get all records from your left table you can use any one of the below 2 methods but i would prefer the 2nd one
1)use sub query
2)first do your aggregation in a separate query and join it with your left table again... the query should be some thing similar to below code:
;WITH CTE ( AccountFK, Debit1 ,Credit1 ,ResDEBIT ,ResCREDIT )
AS (
SELECT
Sales.CustomerInfo.AccountFK
,isnull(SUM(Accounting.DocumentDetail.Debit), 0) AS Debit1
,isnull(SUM(Accounting.DocumentDetail.Credit), 0) AS Credit1
,(
CASE
WHEN (isnull(SUM(Accounting.DocumentDetail.Credit), 0) - isnull(SUM(Accounting.DocumentDetail.Debit), 0)) < 0
THEN (isnull(SUM(Accounting.DocumentDetail.Debit), 0) - isnull(SUM(Accounting.DocumentDetail.Credit), 0))
ELSE 0
END
) AS ResDEBIT
,(
CASE
WHEN (isnull(SUM(Accounting.DocumentDetail.Credit), 0) - isnull(SUM(Accounting.DocumentDetail.Debit), 0)) > 0
THEN (isnull(SUM(Accounting.DocumentDetail.Credit), 0) - isnull(SUM(Accounting.DocumentDetail.Debit), 0))
ELSE 0
END
) AS ResCREDIT
FROM Sales.CustomerInfo
LEFT JOIN Accounting.DocumentDetail ON Sales.CustomerInfo.AccountFK = Accounting.DocumentDetail.TopicFK
GROUP BY Sales.CustomerInfo.CustomerInfoID
,Sales.CustomerInfo.TopicFK
,Sales.CustomerInfo.AccountFK
,Sales.CustomerInfo.AccountNo
,Sales.CustomerInfo.FullName
,Sales.CustomerInfo.Birthdate
,Sales.CustomerInfo.TitleFK
,Sales.CustomerInfo.CompanyRegNo
,Sales.CustomerInfo.PersonTypeFK
,Sales.CustomerInfo.BankAccountDetail
,Sales.CustomerInfo.BankAccountNo
,Sales.CustomerInfo.RegistrationDate
,Sales.CustomerInfo.CustomerPhotoFK
,Sales.CustomerInfo.SocialNo
,Sales.CustomerInfo.WebPage
,Sales.CustomerInfo.JobFK
,Sales.CustomerInfo.MaxDebitLimit
,Sales.CustomerInfo.MaxChequeCredit
,Sales.CustomerInfo.PreferedPaymentMethodFK
,Sales.CustomerInfo.FirstBalanceKind
,Sales.CustomerInfo.FirstBalance
,Sales.CustomerInfo.Debit
,Sales.CustomerInfo.Credit
,Sales.CustomerInfo.Note
,Sales.CustomerInfo.FinancialPeriodFK
,Sales.CustomerInfo.CompanyInfoFK
,Sales.CustomerInfo.BlackListed
,Sales.CustomerInfo.IsActive
)
SELECT Sales.CustomerInfo.CustomerInfoID
,FullTitle = (cast(Sales.CustomerInfo.AccountFK AS NVARCHAR) + ' - ' + Sales.CustomerInfo.FullName)
,Sales.CustomerInfo.TopicFK
,Sales.CustomerInfo.AccountFK
,Sales.CustomerInfo.CompanyRegNo
,Sales.CustomerInfo.PersonTypeFK
,Sales.CustomerInfo.BankAccountDetail
,Sales.CustomerInfo.BankAccountNo
,Sales.CustomerInfo.AccountNo
,Sales.CustomerInfo.FullName
,Sales.CustomerInfo.Birthdate
,Sales.CustomerInfo.TitleFK
,Sales.CustomerInfo.RegistrationDate
,Sales.CustomerInfo.CustomerPhotoFK
,Sales.CustomerInfo.SocialNo
,Sales.CustomerInfo.WebPage
,Sales.CustomerInfo.JobFK
,Sales.CustomerInfo.MaxDebitLimit
,Sales.CustomerInfo.MaxChequeCredit
,Sales.CustomerInfo.PreferedPaymentMethodFK
,Sales.CustomerInfo.FirstBalanceKind
,Sales.CustomerInfo.FirstBalance
,Sales.CustomerInfo.Debit
,Sales.CustomerInfo.Credit
,Sales.CustomerInfo.Note
,Sales.CustomerInfo.FinancialPeriodFK
,Sales.CustomerInfo.CompanyInfoFK
,cte.Debit1
,cte.Credit1
,cte.ResDEBIT
,cte.ResCREDIT
,Sales.CustomerInfo.BlackListed
,Sales.CustomerInfo.IsActive
,CASE
WHEN (ResDEBIT > ResCREDIT)
THEN (ResDEBIT)
WHEN (ResCREDIT > ResDEBIT)
THEN (ResCREDIT)
ELSE 0
END AS Mande
,CASE
WHEN (ResDEBIT > ResCREDIT)
THEN ('debit')
WHEN (ResCREDIT > ResDEBIT)
THEN ('credit')
ELSE ('ziro')
END AS STATUS
FROM Sales.CustomerInfo
LEFT JOIN cte ON Sales.CustomerInfo.AccountFK = cte.AccountFK

Resources