Forum Discussion

erikah06's avatar
erikah06
Helper I
7 years ago
Solved

DAX Create Calculated Field that Performs Calculations Based on Adjacent Field

This my table and respective fields. I would like to create a column called "Availability" which will look at the "STAT" field and determine what operation to perform. If STAT = I0099 or E0002 th...
  • AlB's avatar
    7 years ago

    Hi  erikah06

     

    You want this done per OBNJR? I will assume so. Try this for your new  calculated column, where Table1 is the table you show:

     

    Availability =
    IF (
        NOT Table1[STAT] IN { "I0099", "E0002" },
        DIVIDE (
            Table1[DIF],
            CALCULATE (
                DISTINCT ( Table1[DIF] ),
                Table1[STAT] = "I0099",
                ALLEXCEPT ( Table1, Table1[OBJNR] )
            )
                - CALCULATE (
                    DISTINCT ( Table1[DIF] ),
                    Table1[STAT] = "E0002",
                    ALLEXCEPT ( Table1, Table1[OBJNR] )
                )
        )
    )

     

    On a general note, please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. That allows people trying to help to readily copy the data and increases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

    If you had provided the data in text format, I could have copied easily and run a pretty quick test to make sure the code works as expected.

     

    Cheers

     

    Code formatted with