If then Else using DAX Calculation

Hi all, new to DAX. I am trying to replicate a Oracle SQL column using DAX functions in SSAS Tabular.
My Oracle column is defined like below:
If STATE_CODE Not in('A','B','C','D') 
        And Not (substr(PK_ID,4,2) = 'XY' And DIV_CODE in('YU','SD')) Then
         CNT = 1;
      Else
         CNT = 0;
Any ideas how to start? Should i use DAX Switch function ?
Thanks,
TAG

We have IF and Switch Function Available in DAX .
You can use any of one.
IF(logical_test>,<value_if_true>, value_if_false)
For Switch you can use below;
SWITCH(TRUE(),
booleanexpression1, result1,
booleanexpression2, result2,
else
Just create calculated column in Cube and add this logical IF/Switch function there.
Or If you want to calculate this at query level using DAX then you can follow below Query.
Evaluate
ADDCOLUMNS
TableName,
, "calculated column"
,IF( Logical,Truecondition,False Condition)
Thanks
Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

Similar Messages

  • Query if-then-else logic with calculation

    Hello,
    I want to calculate within a BEX-formula.
    I have two key-figures:
    - Quantity
    - Value
    The logic should be like this:
    IF Value > 0 THEN Value / Quantity ELSE 0
    ( / means: divided)
    How can I reach this?
    The URL
    http://help.sap.com/saphelp_nw70ehp1/helpdata/de/e3/e60138fede083de10000009b38f8cf/frameset.htm
    does not help me.
    Thanks for your help,
    Thomas

    That is the way to perform if then else...
    As long as boolean operations returns 0 or 1 you must play with that in order to get the desired result.
    In case you have DIV problems you can use this operator:
    NDIV0 (x): Is equal to 0 with division by 0, otherwise x.
       NDIV(<Expression>)
    Delivers 0 if the expression named in <Expression> gives a division by 0 in
    the calculation. Otherwise, the result is the value of the expression.
    Is used to
      - Avoid the output of an error message
      - Continue calculating with a defined result
    Please give an example if I am missing something.
    Regards,
    Sebastian,.

  • Problem with if-then-else using BI Answers dataset

    Hi, I'm having issues using the if-then-else logic with a BI Answers dataset. I'm running two versions of a report - one that access the SH schema tables directly, and one that uses a BI Answers dataset based on the SH schema.
    My problem is with the if-then-else operator. It works fine against the relational tables when I use the following syntax:
    <?xdofx:if CUST_GENDER = 'M' then 'Mr.' else 'Ms.' end if?>
    However, when I go against a BI Answers report, the name of the field changes from CUST_GENDER to Customers._Cust_Gender_. If I make an exact find and replace on the if-then-else code, it doesn't work (nothing at all displays)
    <?xdofx:if Customers._Cust_Gender_ = 'M' then 'Mr.' else 'Ms.' end if?>
    Can anyone help?
    Thanks,
    Scott

    Is it possible that any of the fields have null values?  If so, see my blog post about null handling in Crystal for more information:  What is Null and Why is it Important for Crystal Reports | SAP BI BLOG
    -Dell

  • How to do product with sum using DAX

    Hi Everyone,
    How I can get the Value result using DAX:
    Calculation for Value on 3/1/2014: 6*20 + 10*10 + 4*30 = 340 
                                       4/1/2014: 8*30 + 2*10 + 0*40 = 260 .....
    so on...
    Please reply on this...
    Performance of the measure also the big concern

    Especially if you are worried of performance issues, you should use Power Query as a tool for preparing your data before loading into your Power Pivot data model.
    In this case: Unpivot both tables, join them on Date & Currency code and create a new column: CurrVal(from first table) * CurrVal (from second table). Then group on Date, Sum your new value and ignoare Curr-Columns: There
    goes your target value.
    Then directly load to PP data model if you’re using 2013.
    Imke

  • Is there an example to use interface to replace if then else pattern in F#

    is there an example to use interface to replace if then else pattern in F#
    i want to make match pattern with only one rule to represent dynamic number of rules which is use 
    let rec fun1 m number fun2param =
        match m with
        | fun2param(a,b,number) -> ****rewrite terms ****
    let fun2param number =
        if number = 1 then
                 function.....
        elif number = 2 then
                function ....
    computing nightmare

    In general, you use a match
    let fun2param number =
    match number with
    | 1 -> function.....
    | 2 -> function ....
    in the same way as you would use a `switch` construct in 'C' in place of a repeated if/elif...elif/else
    Your request is somewhat vague, so I'm not sure whether you would benefit from wrapping that behind an active pattern.

  • How to use if-then-else-end if in template building?

    hi,
    I am not able to use the "if-then-else-end if" in my template. I want to display a data based on a condition. My requirement is as follows:
    if bal_for_vd < 0 then
    bal_for_vd * no_of_days
    else 0
    end if
    I tried using
    1.<?if: BAL_FOR_VD < 0 then BAL_FOR_VD*NO_OF_DAYS else 0 end if?>
    2.<?xdofx:if BAL_FOR_VD < 0 then BAL_FOR_VD * NO_OF_DAYS end if?>
    3.<?choose:?>
    <?when:BAL_FOR_VD < 0?> <?BAL_FOR_VD * NO_OF_DAYS ?>
    <?end when?>
    <?otherwise?>0
    <?end otherwise?>
    <?end choose?>
    4.<?if:BAL_FOR_VD < 0?><?BAL_FOR_VD*NO_OF_DAYS?><end if?>
    but ended up getting errors or nothing is getting displayed.
    When i used <?BAL_FOR_VD * NO_OF_DAYS ?> alone its working fine and correct getting result. But on giving condition its erring out.
    I will be glad if i get some solution for this.
    Regards,
    Vishnu T Ramakrishnan

    Hi..
    Below syntax should work..I tried with a sample xml..
    <?xdofx:if BAL_FOR_VD < 0 then BAL_FOR_VD * NO_OF_DAYS
      else
    0
    end if?>HTH..

  • Does anyone else use a PDF form to extract data they can then use to populate Dynamic Content in Ill

    Does anyone else use a PDF form to extract data they can then use to populate Dynamic Content in Illustrator?

    You can connect the form to the DB using anODBC connection. This functionality comes as part of Acrobat but the form must be Reader Extended by the full LiveCycle Server version of Reader Extension to allow this in Reader. In your case, if your system is the only on ethat will interact with the DB then this might be a viable solution (but you woudl have to use Acrobat). This solution woudl involve create an ODBC connection in your system then configuring the form to make use of that connection.
    Does that make sense?
    Paul

  • Sum function within if/then/else (xdofx:if)

    I'm attempting to display a total at a particular group within my report. This total is conditional and should choose to display a placeholder value or the sum of another placeholder value (in a child group).
    I have been able to vary my output based on the value I want to check: FIXED_QUOTE_FLAG - I have the if/then/else working in a simplified fashion
    I can display literals and some placeholders correctlly eg. print a literal value of 00110011 or the value of placeholder QUOTED_PRICE
    I can also display a calculated placeholder, using sum within the group I am concerned with: sum (current-group()/ACTIVITY_CHRG)
    But when I try to get everythign working together ...
    I cannot get the sum to work inside the if/then/else condition. The result is NULL (blank in HTML output).
    The following is the snippet which is not working correctly:
    <?xdofx:if FIXED_QUOTE_FLAG = 'Y' then QUOTED_PRICE else sum (current-group()/ACTIVITY_CHRG) end if?>
    Message was edited by:
    gareth_adamson

    To answer you first question, perhaps sum is not a supported function in the xdofx namespace. It's annoying when this problem comes up because xdofx namespace seems to be the only way to do if then else clauses. I'm not entirely certain on the above, but you could resort to using BI Publisher's built-in if statement.
    For your problem, something like this:
    <?if: FIXED_QUOTE_FLAG='Y'?>
    QUOTED_PRICE
    <?end if?>
    <?if: FIXED_QUOTE_FLAG!='Y'?>
    <?sum(current-group()/ACTIVITY_CHRG)?>
    <?end if?>
    EDIT:
    There is a way to do if else without xdofx namespace. It is done with <?choose:?> <?when:?> and <?otherwise:?> tags. Here is example syntax copied from Tim Dexter's blog:
    <?choose:?>
    <?when:count(TRX_NUMBER) > 0?>
    Invoice Table
    <?end when?>
    <?otherwise:?>
    No Data Found
    <?end otherwise?>
    <?end choose?>
    To answer the second question about a running total, you will need to use the <?xdoxslt:set_variable($_XDOCTX,'var_name',var_value)?> and the <?xdoxslt:get_variable($_XDOCTX,'var_name')?>. This method of working with variables is the only method that allows you to update a variable. This makes it good for running totals. Consult the official user guide under "Creating an RTF Template" the section about using variables and calculating running totals.
    So, in your problem, once you get the first part working, you will have to add that value to your running total. It will look something like this:
    <?xdoxslt:set_variable($_XDOCTX,'running_total',xdoxslt:get_variable($_XDOCTX,'running_total') + conditional_value)?>
    Remember to initialize the running total to zero! Hope this helps.
    Thanks,
    Matt Soukup
    Message was edited by:
    Matt Soukup

  • Problem in If-Then-Else formula in report

    Hello guys!
    I use an If-Then-Else statement in a Calculated Key Figure (Cf. <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm">Conditional Calculations</a> ) and it works great with basic calculations.
    I have a query (done in BI 7.0) where I display, for each calendar months (via 0CALMONTH), the usage (stored in a normal key figure in hours) of several products.
    I need to take into account only the products that have been used for at least 60% of the time of the highest product for each month. I a single product, for a month, has been used less than 60% of the highest one, it should be considered as not being used at all (so the calculated usage would be = 0), otherwise, its usage is counted as normal.
    In order to achieve this, I thought I would display the normal usage (the regular key figure) in column A, a calculated key figure that determines the MAXimum usage for each month in column B (which should be the same for all products) and another calculated key figure that displays the result of the If-Then-Else statement in column C.
    In rows, I have 0CALMONTH and the products.
    HOWEVER, when I do this, the result is incorrect. This is probably because to determine the MAX usage, I use a local calculation option, which displays the correct maximum usage on each row but it's not correct when used somewhere else.
    <b>MY QUESTION IS: HOW can I display the maximum usage for a month on all rows without using the calculation option (and therefore would be correctly used by the If-Then-Else statement. I tried an aggregation exception but it doesn't really work (it works only on the total, but I need to do the calculation on each individual row).</b>
    <u><b>Any useful comment will be greatly appreciated </b></u>
    Thanks in advance!

    Hi Francal ,
    Have you tried it . The constant selection will work if you have defined the calculated key figure correctly i.e. Aggreagtiomn "Max" with "product" as ref characteristic. Then you have to use this calculated key figure in your query , restrict it by "product" and make it a constant selection.
    The calculated key figure it self  will bring the highest usage for Month + product + ( any other characteristic you have in query ) but this will only apply to result . If you use constant seelction on top of it it will make sure that you see same value for all product for a particular month( and other characteristic combinations if you have ).
    I have built similar queries and it works . By the way which versions of backend and frontend you have ??
    Regards
    Sanjay

  • How to write Boolean function (If Then Else) For Date Caluclation.

    Dear All,
    I have a scenario where i need to calculate Position time hold by an employee in an organisation.
    I have 2 date Char ( DATE FROM & DATE TO), the problem is that is , If an employee is having
    2/3 position in an organisation its current position End Date is always 31.12.999 as its End date is
    not know. For previous position End Date is maintained.
    My requirement is to calculate Position hold time including Current position.
    Can it be done directly in formula variable with If Then Else condition.
    or i need to write user exit if its exit,
    please guide me for ABAP Code.
    Thanks V V much.
    Regards,

    Hi,
    Following options are available for you:
    1. Is the valid to, valid from dates available as a result of standard time dependency of navigational attributes? if yes , you can not use them in calculations, in such case you may have to write a full fledged routine at formula variable, using uxer exit.
    2. Another simple method, that i would suggest would be using temporal joins (infoSets), that precisely fits you case.
    Helpful links:
    About Infosets:
    [http://help.sap.com/saphelp_nw70/helpdata/EN/ed/084e3ce0f9fe3fe10000000a114084/frameset.htm]
    About Temporal joins:
    [http://help.sap.com/saphelp_nw70/helpdata/EN/11/723c3b35703079e10000000a114084/frameset.htm]
    Hope this helps.
    Cheers,
    Sumit

  • How to use the Calculated attibute in view object

    Hi,
    I have a view object query with the calculated attribute name as 'TRANCODE' in the below sql.This query works for the initial page loading.
    After the page gets loaded, there is a search section in the same page at the top.
    Here i will have to build the whereclause to the same query and retrieve the values.
    i am using jDeveloper 10.1.3.1, with adf and jHeadstart.
    Can some one tell as how to use the calculated attribute TRANCODE in whereclause?
    SELECT /*+ first_rows(10) */
    BatchCntl.FILE_CNTL_ID,
    CASE WHEN chk_bit(Entry.ENTRY_FLAGS, 2)='Y' OR Entry.ENTRY_SUBSTATUS = 'D' OR Entry.ENTRY_SUBSTATUS = 'J'
    THEN
    CASE eeh.TRAN_CODE
    WHEN '21' THEN 'C'
    WHEN '22' THEN 'C'
    WHEN '31' THEN 'C'
    WHEN '32' THEN 'C'
    WHEN '26' THEN 'D'
    WHEN '27' THEN 'D'
    WHEN '36' THEN 'D'
    WHEN '37' THEN 'D'
    ELSE eeh.TRAN_CODE
    END
    ELSE
    CASE Entry.TRAN_CODE
    WHEN '21' THEN 'C'
    WHEN '22' THEN 'C'
    WHEN '31' THEN 'C'
    WHEN '32' THEN 'C'
    WHEN '26' THEN 'D'
    WHEN '27' THEN 'D'
    WHEN '36' THEN 'D'
    WHEN '37' THEN 'D'
    ELSE Entry.TRAN_CODE
    END
    END AS TRANCODE,
    FROM Batch_Cntl BatchCntl, Entry, ENTRY_EDIT_HIST eeh
    WHERE (BatchCntl.BATCH_TYPE = 'E')
    AND (BatchCntl.BATCH_STATUS in ('A','D','R','P'))
    AND entry.in_batch_cntl_id = BatchCntl.BATCH_CNTL_ID
    and Entry.fi_rt = eeh.fi_rt (+)
    and Entry.entry_id = eeh.entry_id (+)
    AND (Entry.ENTRY_STATUS in ('A','D','R','P'))
    ORDER BY BatchCntl.BATCH_CNTL_ID, Entry.entry_id
    regards
    Raj.

    Let's say your application module is com.yourcompany.someapp.services.MyService, and let's say you authored a method like the following in the MyServiceImpl.java file:
      public void doSomething(int i, String s) {
      }and you exposed this AM custom method using the AM editor.
    BC4J design time will automatically create you the com.yourcompany.someapp.services.common.MyService interface that will look like this if you go look at the source code:
    package com.yourcompany.someapp.services.common;
    import oracle.jbo.ApplicationModule;
    public interface MyService extends ApplicationModule {
      public void doSomething(int i, String s);
    }To use your custom method from a client, just cast your ApplicationModule to your custom interface like this:
    import com.yourcompany.someapp.services.common.MyService;
      MyService mySvc = (MyService)yourAM;
      mySvc.doSomething(1,"foo");

  • How to use a calculated column in the same query

    Hi All,
    I need some help with using a calculated column in the same query.
    For eq
    I am joining a couple of tables and some of the select columns are calculated based on the columns of the tables and i want a new column in the same query to use this calculated feild in some other calcualtion.
    something like this...
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    Thanks

    user548171 wrote:
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    ThanksWhat about just repeating the column values:
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( (12+3) / (12-3)  * 100  > 0 )  THEN 'Yes' ELSE 'No'  END FROM DUAL

  • Filtering data already filtered using DAX

    Hi there
    I am using DAX to calculate the count of instances in a filtered table
    e.g.
    =CALCULATE( COUNT(Table[Tariff] ,
    FILTER( Table , Table[Tariff] > 0 )
    This part of the code works fine. My trouble arises when I am trying to filter the table that I have already filtered:
    =CALCULATE( COUNT(Table[Tariff] ,
    FILTER ( FILTER( Table , Table[Tariff] > 0 ) , Table[Tariff] = MIN(Table[Tariff]) )
    In the above calculation, I want to 
    1. Filter out the tariffs that are greater than zero [this bit works fine]; and then
    2. Take that table filtered from 1. above and further filter that by extracting only those tariffs that are equal to the minimum in that data table [this part isn't working].
    Instead of doing what I need it to, this formula is treating the outer FILTER in the same manner that it would be treated if I had only one filter. Thus, as zero is the minimum in the unfiltered data set it is only returning all the zero tariffs - even through
    I filtered these out already.
    If anyone can please assist, it would be much appreciated.
    Cheers
    Andrew

    Hi Andrew,
    Something along these line may work...
    =CALCULATE(
    SUM(TariffData[Tariff])/COUNT(TariffData[Tariff]),
    FILTER(
    FILTER(
    TariffData,
    TariffData[BEGIN_DATE_INDEX] <= [Date_Count]
    && TariffData[END_DATE_INDEX] >= [Date_Count]
    TariffData[Tariff_Duration] = CALCULATE(
    MIN(TariffData[Tariff_Duration]),
    FILTER(
    TariffData,
    TariffData[BEGIN_DATE_INDEX] <= [Date_Count]
    && TariffData[END_DATE_INDEX] >= [Date_Count]
    ...But it's likely that you'll need to adjust the inner most CALCULATE to get the right behaviour due to the filter context transition. If you're able to provide some test data and details of how the data has been modelled, we should be able to arrive at
    a solution that definitely works.
    Regards,
    Michael Amadi
    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
    Website: http://www.nimblelearn.com
    Blog: http://www.nimblelearn.com/blog
    Twitter: @nimblelearn

  • Problem with IF THEN ELSE in RTF template

    HI ALL,
    I have two layouts in the RTF template. Based on the parameter value it has to show the value.
    For example if P_State='United States' then first layout should come. else second one should come.
    I tried to use the IF Then else logic through the form field but i am getting error.
    Please help on this to get it.
    Regards
    Boopathi

    You can do that.
    i guess, the syntax you are using is wrong.
    please refer documentation or this forum for choose:
    Use choose statement. it s better.
    Or send me the template to my id in my profile. or upload it here http://apps2fusion.com/forums/viewforum.php?f=60

  • Select in CASE statement or in IF-THEN-ELSE

    I have been struggling for a week with a problem and still can't solve the way I want.
    Given four text fields in page : p1_name, p1_place_name, p1_place_number and p1_place_init_letter - where user types text and press 'Search' button to see the results.
    p1_name finds results in table EMPLOYEES
    p1_place_name, p1_place_number and p1_place_init_letter find results in table PLACES
    the two tables are linked by id_place field
    I would like reports to be shown depending on search results:
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place = PLACES.id_place then a single report shows only employee row
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place # PLACES.id_place then two reports showing 1) employees with name = :p1_name and 2) places with name, number and init_letter = :p1_.....
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist then a message with 'NO EMPLOYEE' and report shows only places where name, number and init_letter = :p1_.....
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then report shows only employee row where name = :p1_name and message with 'NO PLACE'
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then messages 'NO EMPLOYEE' and 'NO PLACE'
    I do NOT know if it is possible, and if it is, then what do I have to use : IF - THEN - ELSE or CASE ?
    I tried to build HTML report region conditionally shown for each situation, but they do not work the way I want.
    Could you please help me ?
    Thank you in advance !

    Agree with Dan. Use a dedicated report region for a unique query. Use a rendering condition to determine if that reporting region must be rendered (i.e. whether or not that reporting query must be executed ).
    The alternative is creating a function that constructs the SQL query dynamically, based on the user supplied values for page items. Use the function as the source for the reporting region, instead of a SQL statement. (this is similar to creating a ref cursor for a client, minus the actual step to create the ref cursor - instead the source SQL for that ref cursor is returned).
    Also consider asking your Apex questions in the dedicated Apex forum on OTN.

Maybe you are looking for