Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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)

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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

View solution in original post

15 REPLIES 15
TomMartens
Super User
Super User

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

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hey,

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

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

 

Regards Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
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? 

Hey,

 

can you please provide sample of your table 'Last Quarter', also the column [Loan Number].

 

Are there more calculated columns besides Avg. Units in your table?

 

Please have look at this article: http://www.sqlbi.com/articles/understanding-circular-dependencies/

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

I coppied a section of my table in the question. The loan number is just a unique identifier i use to get a count of units. 

 

 

Hey,

 

unfortunately I can't fully reproduce your issue, based on your sample data, due to the missing column that you used for your "Calculated Column".

 

Did you check the other option and did you already checked the article.

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

sorry, yes I looked at the article none of it made sense to me. Not sure what you are missing if it's just the loan number. It's the Units column as a Distinct count to aggregrate it based on my originator. 

 

 

What the article explains, is why you get the error message, so I guess it should mean something.

 

Yes I can't reproduce your issue, because I can't use your formula, to recreate a calculated column (the root case, for the error message) by using calculate.

 

This makes it impossible to help you any further, because the issue can't be recreated by the  data you provided.

 

Regards



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

As i said i'm still new. Thanks for the efforst though 

That's why I was asking for sample data that helps to recreate your issue - helping to solve your issue



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

These are the only three raw data columns i'm using: 

 

Loan NumberTotal Loan AmountLoan Officer
1625282231,900.00Joseph Paul Thweatt
1709173424,100.00Michelle Sue Wickett
17058321,158,700.00Michal Ann Joyner
1617838324,185.00Richard Iain Charles Hobson
1702143311,664.00Bari B Fraire
1707777168,000.00Terry Jo Mays
1707583207,000.00Matt Hennessy
1708565812,000.00Joseph Paul Thweatt
17081345,352.00Tobby James Goicoechea
1709111315,000.00Jennifer Lake
1707930204,000.00Stephen Ray Santi
1704651104,405.00Philip Frank Hickenbottom
1706661311,200.00Nicole Semerad
1708184600,000.00Brady S Spangler
1703546141,750.00Michael Patrick Walsh
1704512248,268.00Kevin Douglas Anderson
17089471,120,000.00Jennifer Lake
1706825106,837.00T.C. Smukalla
1710091132,000.00Amy Julien
1707510185,600.00Lisa Diane Reeder
1710969269,920.00Kenneth Matthew Rife
1708492193,030.00Lynnette Gaye Conley
1706991180,550.00Matthew Daniel Posey
1705058200,000.00Matt Hennessy
1708078210,000.00Julie Marie Pos
1704887315,933.00Maureen Elyse Gilbert
1709381424,100.00Kenneth Matthew Rife
1615352549,000.00Brady S Spangler
1700761215,340.00T.C. Smukalla
1703578592,250.00Richard Iain Charles Hobson
1708934216,015.00Matt Hennessy
1708706295,787.00Nicole Annette Meyerink
1708622657,800.00Brady S Spangler
1708699298,400.00Michelle Sue Wickett
1706499252,345.00T.C. Smukalla
170932967,000.00Lisa Diane Reeder
1706309167,700.00Gregg Driggs

 

 

Rank: Rank = RANKX(ALLSELECTED('Last Quarter'),Calculate(Sum('Last Quarter'[Loan Amount]),AllExcept('Last Quarter','Last Quarter'[C LO Name])),,DESC,DENSE)

 

Total Units: Distinct Count of Loan Number

Total Volume ; Sum of Loan Amount

Avg Units is : CALCULATE(DISTINCTCOUNT('Last Quarter'[Loan Number])/3)

Avg Volume: CALCULATE(SUM('Last Quarter'[Loan Amount])/3)

 

 

Just one final question

 

What are calculated columns and what are measures?

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

They are all calculated columns. 

Anonymous
Not applicable

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

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"

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.