How Do I Write An If Statement in PowerPivot - powerpivot

All,
Just started working with PowerPivot. How do I write a if statement?
I want to see if one value is less than another. If it is, then 0 else 1
=IF(Agent_Daily_Intradiem_TinT[Task Name Count]<Agent_Daily_Intradiem_TinT[Total Task Count]) , 0, 1)

#Derlin's edit was almost perfect except for an extra paren. This is correct.
=IF(Agent_Daily_Intradiem_TinT[Task Name Count]<Agent_Daily_Intradiem_TinT[Total Task Count] , 0, 1)
If you put this as a calculated column it should work. If it is a measure it will fail I believe. Did you want a calculated column?

Related

IcCube - displaying row numbers in icCube Table

In Google Table there is an option to show the row number. But in the other Tables this option is not available unfortunately. We don't use Google Table, since the IcCube Table is just rendering way faster with lots of data.
One workaround we learned about would be to create a calculated measure with a constant value for example : Row as 42 and then setup a custom renderer as following:
function(context) {
return "<span>"+context.getRowIndex()+"</span>";
}
Unfortunately if the table is exported, the constant value (i.e. 42) is displayed and not the row number.
Is there a useful way to get row numbers in the other tables in icCube?
One possibility is to use a calculated member to get the line numbers (it's not going to work with drilldowns).
Assuming you've two axis, the query would look like :
WITH
FUNCTION _currentTuple(_t) as CASE _t.count
WHEN 1 THEN _t.hierarchy.currentMember
WHEN 2 THEN ( _t.Item(0).hierarchy.currentMember,_t.Item(1).hierarchy.currentMember)
// you get the idea
ELSE Error( "_currentTuple- " + Str(_t.count) )
END
MEMBER [Line Position] as Rank( _currentTuple( Axis(1)(0) ) , Axis(1) )
SELECT
[Line Position] on 0,
[Customers].[Geography].[Region].members * [Product].[Product].[Category] on 1
FROM [Sales]
Which make us think we should add a function to get the current axis members in an easier way.
_hope it helps

SQL ignore all blank fields in calculation

I am using the following query in SQL within PhpRunner:
SELECT
[Date],
(MondayStrengthEnd1Sets*MondayStrengthEnd1Reps*MondayStrengthEnd1Distance) + (MondayStrengthEnd2Sets*MondayStrengthEnd2Reps*MondayStrengthEnd2Distance) AS Total
FROM Running
When I run the query I get a blank for an answer. Some of the fields will not necessarily be filled in for every record. The example above is just a snippet of all the fields that is in the table and in the complete calculation, there will be almost 90 fields in total. All the fields are from the same table.
What can I add to the query to treat the blank fields as blanks and not as zeros in order to still calculate the total despite some fields not being filled in? If there is anything that will do it automatically for all the fields it would be great.
I am aiming for something like this:
It looks like you need something like:
SELECT
[Date],
isnull(MondayStrengthEnd1Sets*MondayStrengthEnd1Reps*MondayStrengthEnd1Distance, 0)
+ isnull(MondayStrengthEnd2Sets*MondayStrengthEnd2Reps*MondayStrengthEnd2Distance, 0)
AS Total
FROM Running

Using IF THEN in Access 2010 Query

I'm not very knowledgeable in coding of Access queries, so I hope someone can help with this issue.
I have a query (using the query builder) that has a field named RetrainInterval from table tblProcedures (this will return a number like 1, 3, 6, 12, etc.; the rotational months the particular document have to be retrained on) and another field named Training/Qualification Date from table tblTrainingRecords.
I want the query to look at the RetrainInterval for a given record (record field is ClassID in tblProcedures) and then look at the Training/Qualification Date and calculate if that record should be in the query.
In a module I would do this:
IF RetrainInterval = 1 Then
DateAdd("m",1,[Training/Qualification Date]) <add to query if <=today()+30>
ElseIf RetrainInterval = 3 Then
DateAdd("m",3,[Training/Qualification Date]) <add to query if <=today()+30>
ElseIF......
How can I translate this into something that would work in a query? My end goal is to generate a report that will show me what document class numbers are due within a specified time interval (say I enter 30 in the form textbox to represent any upcoming required training within 30 days of the query), but all of the calculations to determine this is based off of when the last training date was (stored in the training records table). I also want to make sure that I do not get multiple returns for the same class number since there will be multiple training entries for each class, just grab the minimum last training date. I hope I explained it well enough. It's hard to put this into words on what I am trying to do without positing up the entire database.
UPDATE
I think I have simplified this a bit after getting some rest. Here are two images, one is the current query, and one is what comes up in the report. I have been able to refine this a bit, but now my problem is I only want the particular Class to show once on the report, not twice, even though I have multiple retrain due dates (because everything is looking at the table that holds the employee training data and will have multiple training's for each Class number). I would like to only show one date, the oldest. Hope that makes sense.
Query - http://postimg.org/image/cpcn998zx/
Report - http://postimg.org/image/krl5945l9/
When RetrainInterval = 1, you add 1 month to [Training/Qualification Date].
When RetrainInterval = 3, you add 3 months to [Training/Qualification Date].
And so on.
The pattern appears to be that RetrainInterval is the number of months to add. If that is true, use RetrainInterval directly in your DateAdd() expression and don't bother about IF THEN.
DateAdd("m", RetrainInterval, [Training/Qualification Date])
You can not do that in a query. Been there, cursed that!
You can use the IFF( 2>x ; 1 ;0)
Giving that if the first statement is true, 1 is returned, and 0 if false.
You can not return a criteria like IFF(2>x ; Cell>2 ; Cell>0) (Not possible) It will just return 0 if you try, i think. it will not give an error all the time.
You have to use criterias!
I would to something like this picture:
I hope you follow, else let me know.

ssas- how to create calculated measure with logical calculation/computation?

I have a measure(say XX) for a fact but its aggregation type is sum. Now i want to perform a logical case on that i.e if the value of that measure XX is greater than 0 show one else show 0. If I do this with IIF or Case in cube or in excel using olap pivot table extn , I am getting the dim value (against which I will browse this measure) repeatedly / multiple times.
If I use null instead of 0 in IIF or case , I could get the calue but grand total is not shown properly. Also I want that measure XX to act as normal other measures i.e I should be able to browse it against other dims also.
i used the formula available in olap pivot table extension IIF(xx > 0 , 0, 1) (iif(condition , false_val, true_val)) but it causes repetition of dim so i tried iif(xx>0 , 1, null) but can not browse this against multiple dims (same is with case when then end also).
I also tried OLAP pivot table calculation with count and filter function but this is also not giving me desired results. Other approach tried was creating a calculation in cube itself but this also causes the dim populating repeatedly problem . Please let me know if there is some other approach available.

Is there a way to use the condition of an If statement as its value?

This could be a simple question, but it's one I've never seen answered before. Is there a way to use an if statement's condition as its value? This would be really useful in cases where lots of calculation is done to determine if a certain condition is met and if it is, that calculation is the result.
As an example:
if ( [intense calculation] > 0, [same intense calculation], 0)
I'm interested particularly with regards to SQL, as I'm working on a report in Access right now and so can't store the result of the intense calculation in a variable.
Not sure if such a concept exists in the MS Access report world, but how about:
MAX([intense calculation], 0)
The obvious benefit of such an approach is that the calculation would only need to be done once.
One approach in most forms of SQL would be to move the main query to a sub-query, with the intense calculation column aliased and tested in the new outer query - like so:
select v.*,
case intense_calc > 0 then intense_calc else 0 end as positive_calc
from (select [intense calculation] as intense_calc,
[other columns]
from ...) as v