Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dynamically change tolerance value in PowerBI

I have some data that looks something like below:

 

IDValue
A2
A-1
B6
D0

 

Want I want to achieve is to create a new column Category based on the "Value" column, based on if-else rules.

 

E.g.

 

If "Value" < 0, "Category" = "Negative"

elif "Value" > 0, "Category" = "Positive"

else "Category = "OK"

 

I want to be able to add a slicer which defines the threshold for negative/positive. So when I set the slicer at 2, "Category" will only become "negative" when "Value" < -2 and "positive" when "Value" > 2

 

What I tried:

 

I created a table with values 0 - 5, which serves as the basis for my slicer (single select a value 0-5).

 

1. Create additional column in my table, one for each possible value in the slicer and create a measure that selects a column using SWITCH. Very ugly solution & gives me the error that multiple columns cannot be converted to a scalar value. 

 

2. create a measure like below:

measure =

var selected = SELECTEDVALUE('slicer table'[value])
return ADDCOLUMNS(main table, "category", IF(main table[Value] < -selected, "Negative", IF(main table[Value] > selected, "Positive", "OK")))
 
Same error as in 1.
 
Question
How do I create a measure that let's me incorporate a tolerance for defining categories in a column?
 
I know it's not possible to create dynamically calculated columns in PBI, but I guess this should be possible using a measure. I just don't see how I can avoid the aggregation, I just need the entire column to be returned and plot that in something like a pie chart for example. But since in a broader sense I'm just trying to incorporate a tolerance this is probably a use-case that occurs more often. So I would imagine it to be possible, I'm just not experienced enough with PBI to figure it out.
 
Any help is appreciated!
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Check the formula. You could create a slicer table and use selectedvalue('slicer'[value]) to replace the zero in the formula.

    Measure = SWITCH(TRUE(),SELECTEDVALUE('Table'[Value])>0,"Positive",SELECTEDVALUE('Table'[Value])<0,"Negative",SELECTEDVALUE('Table'[Value])=0,"OK")

    There are multiple values for a single id, please check the "Don't summarize" option to avoid the aggregation.

    You mentioned you want to create a Pie chart, but Pie chart doesn't support "Don't summarize". And Pie chart also doesn't support to put measures to the value field.

    In addition, I don't know how you want to display the positive and negative values in Pie chart. So, if you want further help please share more details.

     

    Best Regards,

    Jay

3 Replies

  • Anonymous , You have to create a measure like with help from a what if Param

     

    Measure =

    var _1 = Sum(Table[Value])

    Switch( True(),

      _1 < selectedvalues(Param[Param]) ,  "Negative"

      _1 > selectedvalues(Param[Param]),  "Positive"

     "OK")

     

    You need to have a table(bucket)  with three rows

    Negative

    Positive

    OK

     

    Then you need a measure like

    Sumx(filter(Values(Table[ID]), [Measure] = max(bucket[Value])) , [Measure])

     

    refer

    Dynamic Segmentation Bucketing Binning
    https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1387187#M626


    Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks amitchandak, one follow-up question though. I don't understand Sumx(filter(Values(Table[ID]), [Measure] = max(bucket[Value])) , [Measure]), what do you mean by bucket[Value]? The categories, but then MAX() function will not work. Or the value which the label belongs to, but then this won't by dynamic with my slicer right?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Check the formula. You could create a slicer table and use selectedvalue('slicer'[value]) to replace the zero in the formula.

    Measure = SWITCH(TRUE(),SELECTEDVALUE('Table'[Value])>0,"Positive",SELECTEDVALUE('Table'[Value])<0,"Negative",SELECTEDVALUE('Table'[Value])=0,"OK")

    There are multiple values for a single id, please check the "Don't summarize" option to avoid the aggregation.

    You mentioned you want to create a Pie chart, but Pie chart doesn't support "Don't summarize". And Pie chart also doesn't support to put measures to the value field.

    In addition, I don't know how you want to display the positive and negative values in Pie chart. So, if you want further help please share more details.

     

    Best Regards,

    Jay