Dynamic Title (Card Visual) based on SelectedValue - switch-statement

I try to implement a dynamic title (card visual) based on selectedValues of filters.
I have tried this:
Title = SWITCH( True();
SELECTEDVALUE(Daten[Contact Name]); "Aufgaben von " & SELECTEDVALUE(Daten[Contact Name]);
SELECTEDVALUE(Daten[Buchungs Datum].[Year]); "Aufgaben vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]);
SELECTEDVALUE(Daten[Verkäufer]); "Aufgaben von Verkäufer: " & SELECTEDVALUE(Daten[Verkäufer]);
SELECTEDVALUE(Daten[Contact Name]) & SELECTEDVALUE(Daten[Buchungs Datum].[Year]); "Aufgaben von " &SELECTEDVALUE(Daten[Contact Name]) & " vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]);
SELECTEDVALUE(Daten[Buchungs Datum].[Year]) & SELECTEDVALUE(Daten[Verkäufer]); "Aufgaben vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]) & " vom Verkäufer: " & SELECTEDVALUE(Daten[Verkäufer])
)
I try to catch each possibilities of the applied filters. Bases on the applied filters the title card will dynamically change.
True doesn't work witch cases of type selectedvalue. Which makes sence, but now i dont know really how to get the result i want.
Is there any suggestion how I could implement this measure differently? Thank you.

If I got it right you are trying to return a string, based on the current selections made by the user.
"SELECTEDVALUE()" returns the column value if there is only one value selected, otherwise an optional default value. The returned value is the column value itself (number/string/date) whatever the column contains, not strictly true/false.
In order to make it work, you may want to use "HASONEVALUE()" which returns what you need
Title =
SWITCH( True();
HASONEVALUE(Daten[Contact Name]) && HASONEVALUE(Daten[Buchungs Datum].[Year]); "Aufgaben von " & SELECTEDVALUE(Daten[Contact Name]) & " vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]);
HASONEVALUE(Daten[Buchungs Datum].[Year]) && HASONEVALUE(Daten[Verkäufer]); "Aufgaben vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]) & " vom Verkäufer: " & SELECTEDVALUE(Daten[Verkäufer]);
HASONEVALUE(Daten[Contact Name]); "Aufgaben von " & SELECTEDVALUE(Daten[Contact Name]);
HASONEVALUE(Daten[Buchungs Datum].[Year]); "Aufgaben vom Jahr " & SELECTEDVALUE(Daten[Buchungs Datum].[Year]);
HASONEVALUE(Daten[Verkäufer]); "Aufgaben von Verkäufer: " & SELECTEDVALUE(Daten[Verkäufer])
)
Also, the AND operator (used in the last two cases) is "&&", not "&".
You may improve the readability of this expression by using some variables, especially if the formula will get longer.
Edit:
The most restrictive expressions must be at the top, otherwise, a less restrictive condition will be triggered. ie:
HASONEVALUE(Daten[Contact Name]) && HASONEVALUE(Daten[Buchungs Datum].[Year])
-- since this a "subset" of the previous one, it will be true in the same moment.
-- if it's evaluated before the other one (in the switch) then the other will never be evaluated
HASONEVALUE(Daten[Contact Name])

Related

Table labeling and referencing in Rmarkdown

I'm using markdown to render in PDF format.
I am able to cross-reference plot, but when I build a table in LaTeX, I can't do it somehow. An example:
We plot in Figure \#ref(fig:plotseries) the three Index series and their log return series. In Table \#ref(tab:summindex_stargazer) the main characteristics...
while the table has been coded as follow:
\begin{table}[!htbp] \centering
\caption[Summary statistics for token indexes under study.]{Summary statistics for large cap (L.MWI), medium cap (M.MWI), and small cap (S.MWI) indexes log return series. \label{tab:summindex_stargazer}}
\footnotesize
\begin{tabular}{#{\extracolsep{5pt}} cccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& L.MWI Returns & M.MWI Returns & S.MWI Returns \\
\hline \\[-1.8ex]
nobs & $1,524$ & $1,380$ & $1,362$ \\
NAs & $0$ & $0$ & $0$ \\
Minimum & $-0.351$ & $-0.549$ & $-0.933$ \\
Maximum & $0.464$ & $0.699$ & $1.010$ \\
1. Quartile & $-0.031$ & $-0.034$ & $-0.052$ \\
3. Quartile & $0.036$ & $0.039$ & $0.050$ \\
Mean & $0.003$ & $0.004$ & $0.002$ \\
Median & $0.002$ & $0.004$ & $-0.003$ \\
Sum & $4.144$ & $5.333$ & $2.863$ \\
SE Mean & $0.002$ & $0.002$ & $0.004$ \\
LCL Mean & $-0.001$ & $0.000$ & $-0.005$ \\
UCL Mean & $0.006$ & $0.008$ & $0.009$ \\
Variance & $0.004$ & $0.005$ & $0.017$ \\
Stdev & $0.066$ & $0.073$ & $0.130$ \\
Skewness & $0.236$ & $0.214$ & $1.000$ \\
Kurtosis & $4.355$ & $11.602$ & $13.393$ \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
This is the result.
Found out the solution. Basically you are not allowed to use “underscore”(_) in table labels.
It was so simple but also so incredibly hard to find out (I personally know many people who’d encountered this error and were not able to solve it). I hope it will help.
Adding to what is written here, underscores are one of 10 special characters in LaTeX.
For underscores to be permitted in table labels they need to be escaped.
This should work:
\#ref(tab:summindex\_stargazer)
But not this:
\#ref(tab:summindex_stargazer)
See this discussion for an excellent reference on special characters.

Object Defined or Application Defined Error, Formula String

I seem to be having a type mismatch error in the below formula. Numbering, Approval, PeakShare, and RampUp are all stored as ranges, app as an integer. I believe I have escaped my quotes correctly in trying to include the value of 'app'. But I get a "Type mismatch" error in return. I have also tried including a non-variable integer and receive an "Object defined or application defined error." I have read some things about the use of indirect and approval in Excel formulas but haven't found much out there with its use in VBA, is this the problem?
formulaUp = "=IF(" & Numbering.Address(True, False) & "<" & Approval.Address & ","""", " & PeakShare.Address & " * " & RampUp.Offset(0, -"" & app & "" + 1).Address(True, False) & ")"
The type mismatch comes from
RampUp.Offset(0, -"" & app & "" + 1)
The second argument you are trying to pass to Offset does not make much sense, and throws because according to operator precedence it's (-"") & app & ("" + 1), and neither of the bracketed expressions can be calculated.
Apparently you meant
RampUp.Offset(0, -app + 1)

Delete table in access with String with 3 values

Good day,
Im getting an error (syntax error missing operator in a query expression for "and monitorNumber = Monit)
SQLDel = "DELETE FROM HBAU WHERE Peoplesoft ID ='" & PSID & "' and DATE =#" & InputDate & "# and MonitorNumber = Monit"
can anyone tell me whats missing...
If Monit is VBA variable, try this one:
SQLDel = "DELETE FROM HBAU WHERE [PeoplesoftID] =" & PSID & " and [DATE] =#" & InputDate & "# and [MonitorNumber] = " & Monit
also should Peoplesoft ID be PeoplesoftID? Note if your PeoplesoftID has numeric type, you don't need single quotes around PSID.
Aslo you may want to read this: Global Variables in SQL statement

Excel Amount in Words Formula

I found this formula below to convert amounts to words for google spreadsheets and it works perfectly. But now I want to use it in excel 2010 and I get a lot of errors. I also cannot use VBA. Thanks for any help.
=if(or(isBlank(A1),not(isNumber(A1)),A1>=power(10,15)),ifError(1/0,"Error"),trim(arrayFormula(concatenate(if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))<100,"",choose(int(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))/100)," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine") & " Hundred") & if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<>0,if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))>100," And",if(A1>power(10,{15,12,9,6,3}),choose({1,2,3,4,5},"","","",""," And"),"")),"") & if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)=0,"",if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<20,choose(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"),choose(int(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)/10),""," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety") & if(mod(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),10)=0,"","-" & choose(mod(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),10),"One","Two","Three","Four","Five","Six","Seven","Eight","Nine")))) & if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))=0,"",choose({1,2,3,4,5}," Trillion"," Billion"," Million"," Thousand","")))) & if(A1>=2," Rand",if(A1>=1," Rand","")) & if((round(A1-trunc(A1),2)*100=0)+(A1<1),""," And") & if(round(A1-trunc(A1),2)*100=0,"",if(round(A1-trunc(A1),2)*100=1," One Cent",if(round(A1-trunc(A1),2)*100<20,choose(round(A1-trunc(A1),2)*100," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"),choose(int(round(A1-trunc(A1),2)*100/10),""," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety") & if(mod(round(A1-trunc(A1),2)*100,10)=0,"","-" & choose(mod(round(A1-trunc(A1),2)*100,10),"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"))) & " Cent"))))
If your numbers do not need to go above ~100, it may be easier to make two columns, the first with the 1,2,3 etc. and the second with one,two,three etc. Then you can do VLOOKUP() on that table.
An example can be found here: https://www.dropbox.com/s/e44dnkg3he8b8il/NumericalToAlpha.xlsx

Help with function in string

I have a variable, emailBody, which is set to a string stored in a database. The email body is set to a string via a dlookup function.
emailBody = DLookup("emailBody", "listAdditions", "Id = " & itemType)
The string that email body is set to includes an IIf function (which includes a dlookup function). When
?emailBody is entered in the immediate window during runtime, it shows that emailBody is set to the following string:
The new commodity is" & Iif(dlookup("IsVague", "CommodityType", "Description= " & newItem)="1", "vague.", "not vague.")
However, I want the dlookup and IIf functions to be evaluated and their results stored in the string. How do I properly format the emailBody string ("the new commodity...") in my database so that the functions will be evaluated and the results stored in the emailBody variable?
Your question is a bit unclear, but if [Id] (Or [Description]) is a string, then you Dlookup must be like this:
emailBody = DLookup("emailBody", "listAdditions", "Id = '" & itemType & "'")
or
emailBody = DLookup("emailBody", "listAdditions", "Id = """ & itemType & """")
That is, your constant should be surrounded by quotes. You can either use ' (single quote) or "" (doubled double quote).
I am somewhat concerned about the value of newitem, but in general you can use Eval:
s = """The new commodity is"" & " _
& "Iif(dlookup(""IsVague"", ""CommodityType"", ""Description= "" & newItem)=""1"", ""vague."", ""not vague."")"
s2 = Eval(s)
I am not sure that this is the way to go, think about it.
So you have this exact string stored in a table field, and you want Access/VBA to evaluate it, correct?
"The new commodity is " & Iif(dlookup("IsVague", "CommodityType", "Description= " & newItem)="1", "vague.", "not vague.")
If so, try the Eval() command:
emailBody = Eval(DLookup("emailBody", "listAdditions", "Id = " & itemType))

Resources