Code to compare the number of "false" to total number of cases - tableau-api

I am trying to create a chart in tableau which will show me the comparison in weeks, i.e. the comparison between the trend from week 1 to week 5.
In simple terms it should be like:
If Verdict = "Not Reversing" THEN count the total number of Verdicts
Else do not count
If IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
IF [Verdict] = "Not Reversing"
THEN
COUNT([Verdict])
END
Error message shows cannot mix aggregate and non aggregate functions

Assuming your data source has exactly one data row per verdict ... (Always be clear about what one row in your data source represents.)
You could define a calculated field called Number of Non Reversing Verdicts defined as INT([Verdict] = "Non Reversing") That field will have the value 1 for Non Reversing verdicts and 0 otherwise. The INT() function converts its arguments into an integer, and treats TRUE as 1 and FALSE as 0.
You can then plot SUM([Number of Non Reversing Verdicts]) as desired, along with SUM([Number of Records]) to see the total number of verdicts -- or even compute the ratio of the two formatted as a percentage.
For extra credit, you could rename the predefined field [Number of Records] to [Number of Verdicts] for this data source if that helps make it more clear. (BTW, look at the definition of [Number of Records] and make sure you understand why that works)

Related

Look up an account then average associated values excluding zeros

On one sheet, I have account code and in the cell next to it, I need to look up the account code on the next sheet to average the cost excluding those cells that are zero in col. b from the average calculation.
The answer for London should be: £496.33 but having tried various sumifs / countifs I cannot get it to work.
You probably need COUNTIFS which -- similar to the SUMIFS you are already using -- allows to define multiple critera and ranges.
So, if the column R contains the values, you want to build the average upon, and the column H in the respective row must equal $B$28 to be included in the sum, the respective COUNTIFS looks as follows
=SUMIFS('ESL Info'!$R:$R,'ESL Info'!H:H,$B$28)/COUNTIFS('ESL Info'!$H:$H,$B$28, 'ESL Info'!$R:$R, "<>0")
ie additionally to the value in the H-column to equal B28 it also requires the value R-column (ie the actual number you are summing up) to be different from 0
You could also add the same criteria 'ESL Info'!$R:$R, "<>0" to your SUMIFS, but that isn't necessary, because a 0 doesn't provide anything to you sum, thus it doesn't matter if it's included in the sum or not ...
And depending on the Excel version you are using, you may even have the AVERAGEIFS function available, which does exactly what you want
=AVERAGEIFS('ESL Info'!$R:$R,'ESL Info'!$H:$H;$B$28,'ESL Info'!$R:$R,"<>0")

Two conditions on one formula field

I have a field, which takes values less than zero & greater than zero.
Also in that field, Values will be having leading zeros.
So I have used the following conditions like
Replace({Command. Field}, "0",".") and
If {Command. Field} < 0
then ((Int(tonumber({command. Field}))) *1000)
When I save the formula getting error like "A Boolean is required here"
Why I am getting this error?
Since this field has values less than zero & I want to automatically multiple that value with 1000 to get the desired output.
Is it possible to give both of the conditions in single formula?

MATLAB Extracting Column Number

My goal is to create a random, 20 by 5 array of integers, sort them by increasing order from top to bottom and from left to right, and then calculate the mean in each of the resulting 20 rows. This gives me a 1 by 20 array of the means. I then have to find the column whose mean is closest to 0. Here is my code so far:
RandomArray= randi([-100 100],20,5);
NewArray=reshape(sort(RandomArray(:)),20,5);
MeanArray= mean(transpose(NewArray(:,:)))
X=min(abs(x-0))
How can I store the column number whose mean is closest to 0 into a variable? I'm only about a month into coding so this probably seems like a very simple problem. Thanks
You're almost there. All you need is a find:
RandomArray= randi([-100 100],20,5);
NewArray=reshape(sort(RandomArray(:)),20,5);
% MeanArray= mean(transpose(NewArray(:,:))) %// gives means per row, not column
ColNum = find(abs(mean(NewArray,1))==min(abs(mean(NewArray,1)))); %// gives you the column number of the minimum
MeanColumn = RandomArray(:,ColNum);
find will give you the index of the entry where abs(mean(NewArray)), i.e. the absolute values of the mean per column equals the minimum of that same array, thus the index where the mean of the column is closest to 0.
Note that you don't need your MeanArray, as it transposes (which can be done by NewArray.', and then gives the mean per column, i.e. your old rows. I chucked everything in the find statement.
As suggested in the comment by Matthias W. it's faster to use the second output of min directly instead of a find:
RandomArray= randi([-100 100],20,5);
NewArray=reshape(sort(RandomArray(:)),20,5);
% MeanArray= mean(transpose(NewArray(:,:))) %// gives means per row, not column
[~,ColNum] = min(abs(mean(NewArray,1)));
MeanColumn = RandomArray(:,ColNum);

Tableau: Finding an attribute count from ONLY distinct rows

I can't seem to find a solution for my issue anywhere, and I hope that I can ask my question correctly here to find an answer:
I am having a problem finding a count of the number of values from only the distinct rows in my dataset.
In my Tableau sheet, I am trying to find the number of cases that are closed as "FCR" - and in the database, this is represented as true or false.
My formula:
SUM(if [IsFCR] = true then 1 else 0 end)
The problem that I am running into is that this is getting the count from all of the rows in my data. But I need represent the total cases, and the FCR value from each of THOSE rows as a distinct count.
As seen in this image: Screen capture of Tableau formula
I am returning 9,000 distinct rows - but 46,000 counts of FCR being true.
Notably, I have tried wrapping my formula in a COUNTD (and it returns 2), in Window_Count (returns 1), among many other guesses as to how I could wrap this calculated field in a way to only count the unique rows.
If only I could use a foreach logic...
Any help that you can give is greatly appreciated.

Can't Sum Formula in Crystal Reports

I am trying to sum two different formula fields in Crystal. It will not let me select them from the Sum. The first formula is
if Sum ({tblPostedLine.pli_QUANTITY_SHIPPED}) >= 1
then {tblPostedLine.pli_NET_PRICE}
else ({tblPostedLine.pli_NET_PRICE} * -1)
I am trying to take a price and make it a negative value if the quantity is a negative value. I then want to sum the amounts to get a net amount that was shipped.
The other formula is
If PreviousIsNull({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
or ({RodsvwCatalogAnalysis.pro_PROMOTION_CODE}) <>
Previous({RodsvwCatalogAnalysis.pro_PROMOTION_CODE})
then {RodsvwCatalogAnalysis.pit_AREA_PER_PAGE} else 0
With this formula, I am trying to sum at a group level, not the details level. When I just sum the group level number, it is adding it every time the value is listed in the details as well.
I am open to any suggestions.
Thanks!
For the first scenario,
Create 1 variable formula in detail level to hold with your requirement.
for e.g.
#NetPrice , formula if {tblPostedLine.pli_QUANTITY_SHIPPED} >= 1 then
{tblPostedLine.pli_NET_PRICE} else ({tblPostedLine.pli_NET_PRICE} * -1)
using running total field feature in your Field Explorer to sum up the value and place
your group footer.
For the second scenario, I believe it relate to promotion group and again you could use the running total field feature to evaluate the sum condition and reset the value when condition are meet like field value change.