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

How to calculate columns based on slicer selection

Hi,

there is a slice its called target. user can select target between 1% and 99% .

i need to re-calculate dimention every time user select new value. this deminsion is used as legend in Stacked area chart.

formula looks like:

Payload Target Group = SWITCH(TRUE(),
'Table1'[Payload Target] =0 , "No Target"
,'Table1'[Payload] =0 , "NO Payload"
,DIVIDE('Table1'[Payload] , 'Table1'[Payload Target]) < (1- DIVIDE(Ds_target[Ds_TargetSelectedValuet],1)) , "Underload"
,DIVIDE('Table1'[Payload], 'Table1'[Payload Target]) > (1+ DIVIDE(Ds_target[Ds_TargetSelectedValuet],1) ), "Overload"
,"Within Limit"
)

Report:

bahman7210_2-1615506614362.png

 

 

Any idea how can i do it?

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Create a dimension table as below:

v-kelly-msft_0-1616032412600.png

If you wanna get an average grade in the related legend,create a measure as below:

_rate1 = 
var _Top=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Top"))
var _Good=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Good"))
var _NotBad=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Not Bad"))
var _Tryagain=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Try again"))
Return
 SWITCH(
    SELECTEDVALUE('dim table'[Category]),
    "Top",AVERAGEX(_Top,[grade]),
    "Good",AVERAGEX(_Good,[grade]),
    "Not Bad",AVERAGEX(_NotBad,[grade]),
    "Try again",AVERAGEX(_Tryagain,[grade]))

Put the dimension field as legend,and you will see:

v-kelly-msft_1-1616032606113.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

16 REPLIES 16
amitchandak
Super User
Super User

@Anonymous , You can not create a column, based on slicer selection.

 

You need to create a measure or do segmentation with measure

 

https://www.daxpatterns.com/dynamic-segmentation/
https://radacad.com/grouping-and-binning-step-towards-better-data-visualization
https://youtu.be/CuczXPj0N-k

Anonymous
Not applicable

these are dimensions 'Table1'[Payload] , 'Table1'[Payload Target]

i need to calculate it row by row

Hi @Anonymous ,

 

Could you pls provide some sample data with expected output for test?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

 

Anonymous
Not applicable

Please download file from below linke

 

https://drive.google.com/drive/folders/1_MvzUYXC9c6IMohfXrGAhyEjF1pmDjyt?usp=sharing

 

 

i made it more convenient, look at rate column

aj1973
Community Champion
Community Champion

@Anonymous 

what do you want to see as an Output?

Your measure and the tables don't existe in your Pbix file!

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

i made it simple. i need to calculate rate base on drop down value .

if grade = 100 rate is "Top"

grade + value >100 then "good"
grade + value >90 then "not bad"

 

Hi  @Anonymous ,

 

You'd better create a measure instead of a calculated column,see below:

_rate = 
SWITCH(TRUE(),
MAX('Student'[grade])=100,"Top",
MAX('Student'[grade])+'TargetTable'[TargetSelectedValue]>100,"good",
MAX('Student'[grade])+'TargetTable'[TargetSelectedValue]>90,"not bad","try more")

And you will see:

v-kelly-msft_0-1615862176760.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Thank you, now its pretty

actually my formula is a bit complex, i added new column to source and its called Sclae , formula changed to 


_rate =
SWITCH(TRUE(),
MAX(Student[grade]) =100 , "Top",
DIVIDE( MAX(Student[grade]) ,MAX(Student[Scale])) < 1 - [TargetSelectedValue] , "Good",
DIVIDE( MAX(Student[grade]) ,MAX(Student[Scale])) > 1 + [TargetSelectedValue] , "Not Bad",
"try more"
)

 

result is not as my expectation

 

here is file

https://drive.google.com/drive/u/0/folders/1_MvzUYXC9c6IMohfXrGAhyEjF1pmDjyt

 

aj1973
Community Champion
Community Champion

@Anonymous 

What are your expectations? if this is the picture

aj1973_0-1615922204372.png

Where 

X = DIVIDE( MAX(Student[grade]) ,MAX(Student[Scale]))
Y = 1 - [TargetSelectedValue]
Z = 1 + [TargetSelectedValue]
Thats what you have in your Formula __rate

_rate =
SWITCH(TRUE(),
MAX(Student[grade]) =100 , "Top",
X < Y , "Good",
X > Z , "Not Bad",
"try more"
)

 

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

i want to use new calculation as legend in stacked area chart. but cant add measure as legend

aj1973
Community Champion
Community Champion

Measures are not columns type of thing therefore they can't be used as legend 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

so do you mean i can not create this report in powerbi ?
to summarize my issue:

1- there is drop down for target

2- Want to calculate target-value, measure should be created !

3- measure cant show info in legend !

is there any solution ?

 

Hi @Anonymous ,

 

Create a dimension table as below:

v-kelly-msft_0-1616032412600.png

If you wanna get an average grade in the related legend,create a measure as below:

_rate1 = 
var _Top=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Top"))
var _Good=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Good"))
var _NotBad=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Not Bad"))
var _Tryagain=CALCULATETABLE(VALUES('Student'[grade]),FILTER(ALL(Student),'Student'[_rate]="Try again"))
Return
 SWITCH(
    SELECTEDVALUE('dim table'[Category]),
    "Top",AVERAGEX(_Top,[grade]),
    "Good",AVERAGEX(_Good,[grade]),
    "Not Bad",AVERAGEX(_NotBad,[grade]),
    "Try again",AVERAGEX(_Tryagain,[grade]))

Put the dimension field as legend,and you will see:

v-kelly-msft_1-1616032606113.png

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi @Anonymous ,

 

Yes,measure cant be used as  legend,but calculated column can,the link of your .pbix file is not available,could you pls reshare it?If possible,could you pls also attach your expected output?

 


Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Link : https://drive.google.com/drive/folders/1_MvzUYXC9c6IMohfXrGAhyEjF1pmDjyt?usp=sharing

 

1- so there is not any way to create calculated column based on target (drop down list) ?

2- need to upgrade rate formula to

_rate =
SWITCH(TRUE(),
MAX(Student[grade]) =100 , "Top",
DIVIDE( MAX(Student[grade]) ,MAX(Student[Scale])) < 1 - [TargetSelectedValue] , "Good",
DIVIDE( MAX(Student[grade]) ,MAX(Student[Scale])) > 1 + [TargetSelectedValue] , "Not Bad",
"try more"
)

 

 

 

aj1973
Community Champion
Community Champion

"You can not create this report in Power BI?" With Power Bi you can create inimaginable kinds of report. 

Your Summary of the issues are not very clear eventhough I think we helped you with it.

Maybe there is some limitation for now as Microsoft is updating Power Bi every month so you might as well through a ticket to Microsoft for a better solution.

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

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.