Search code examples
powerbidaxm

Conditional calculation based on another column


I have a cross reference table and another table with the list of "Items"

I connect "PKG" to "Item" as "PKG" has distinct values.

 Example:

 **Cross table**              **Item table**
  Bulk   PKG                    Item  Value
  A        D                      A     2     
  A        E                      B     1     
  B        F                      C     4    
  C        G                      D     5   
                                  E     8     
                                  F     3   
                                  G     1    

After connecting the 2 above tables by PKG and ITEM i get the following result

 Item  Value  Bulk  PKG
   A     2 
   B     1
   C     4
   D     5      A     D
   E     8      A     E
   F     3      B     F
   G     1      C     G

As you can see nothing shows up for the first 3 values since it is connected by pkg and those are "Bulk" values.

I am trying to create a new column that uses the cross reference table

I want to create the following with a new column

      Item  Value  Bulk  PKG   NEW COLUMN
        A     2                    5
        B     1                    3
        C     4                    1
        D     5      A     D       5.75
        E     8      A     E       9.2
        F     3      B     F       3.45
        G     1      C     G       1.15

The new column is what I am trying to create.

I want the original values to show up for bulk as they appear for pkg. I then want the Pkg items to be 15% higher than the original value.

How can I calculate this based on the setup?


Solution

  • Just write a conditional custom column in the query editor:

    New Column = if [Bulk] = null then [Value] else 1.15 * [Value]
    

    You can also do this as a DAX calculated column:

    New Column = IF( ISBLANK( Table1[Bulk] ), Table1[Value], 1.15 * Table1[Value] )