Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

IF Function

Hello, 

I'm still learning all of this DAX and Power BI function writing. I am trying to get the below to break out a column into 3 levels? It's only picking up the GOLD level. 

 

Unit Level = IF(SUM([Avg. Units])<9,"Blue",IF(SUM([Avg. Units])>=18,"Gold","Silver"))

OriginatorTotal UnitsTotal VolumeAvg. UnitsAvg. VolumeUnit Level
Spangler, Brady62$26,621,48520.66666667$8,873,828Gold
Hennessy, Matt55$12,639,67718.33333333$4,213,226Gold
Wickett, Michelle46$10,607,46415.33333333$3,535,821Gold
Smukalla, TC28$9,190,5679.333333333$3,063,522Gold
Sparks, Suzie19$8,625,0076.333333333$2,875,002Gold
Shtatman, Matthew32$8,512,15710.66666667$2,837,386Gold
Hobson, Richard18$8,446,1106$2,815,370Gold
Meyerink, Nicole25$7,390,5238.333333333$2,463,508Gold
Tschernia, Paul28$7,303,7909.333333333$2,434,597Gold
Julien, Amy30$6,798,51610$2,266,172Gold
Laughlin, Patrick18$6,171,3516$2,057,117Gold
Eaton, Julia14$6,161,5854.666666667$2,053,862Gold
Robertson, Rick13$6,013,6904.333333333$2,004,563Gold
Walsh, Michael24$5,822,7718$1,940,924Gold

 

My Avg Units Column is the sum of a calculated column so not sure if that is my hang up 

Avg. Units = CALCULATE(DISTINCTCOUNT('Last Quarter'[Loan Number])/3)

  • Anonymous's avatar
    Anonymous
    8 years ago

    I figured it out!!!! I had to make my expression a measurement and not a calculated column!!!! So embarassed thank you for your help~! 

15 Replies

  • Hey,

     

    I assume that Unit Level is also a calculated column.

     

    Put the expression inside a CALCULATE( ... ) this should solve your problem.

     

    Using SUM(...) means always aggregate the available rows of the table considering the current Filter Context.

    Definig a calculated column one has to consider that there is no Filter Context, just a Row Context. This means using SUM(...) aggregates all the rows, for this reason you just have "Gold".

     

    Two possibilities

    • Wrap CALCULATE around the expression. CALCULATE( ) introduces  a Filter Context. Using CALCULATE() inside a Row Context means, the Filter Context is just the current row, this of course can be changed by adding more than just the 1st parameter - the expression.
    • Remove the SUM()s from your expression, to reference a value from a certain column inside a Row Context it's not necessary to use SUM

    Hope this helps

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      THe Unit Level Calculation is Unit Level = IF(SUM([Avg. Units])<9,"Blue",IF(SUM([Avg. Units])>=18,"Gold","Silver"))

       

      If I add calculate to this i get a "Circular Dependency was detected"

       

       

    • TomMartens's avatar
      TomMartens
      Super User

      Hey,

      this will resolve the error message
      CALCULATE(
      < your expression >

      ,ALLEXCEPT('yourtablename', 'yourtablename'[name of the calculated column 1])
      )

       

      Regards Tom

      • Anonymous's avatar
        Anonymous
        Not applicable

        Ok SO update my expression to : 

         

        Unit Level = CALCULATE(IF(SUM([Avg Units])<9,"Blue",IF(SUM([Avg Units])>=18,"Gold","Silver")),ALLEXCEPT('Last Quarter','Last Quarter'[Avg Units]))

         

         

        but still getting all gold results. This shouldn't be this hard. What am I missing?