Forum Discussion
Best Way to Create Column that First Calculates Range, then Assigns Value
I am new-ish to creating columns in the Query, and can use help finding the best way to create this calculation. This is my data and range:
Project | RATE | APE | CostDiff | CostHealth |
1 | $156.60 | $145.67 | -$10.93 |
|
2 |
| $29.80 |
|
|
3 | $57.26 | $57.20 | -$0.06 |
|
4 | $16.51 | $21.24 | $4.73 |
|
5 | $52.48 | $54.70 | $2.22 |
|
6 |
| $19.17 |
|
|
7 | $59.01 | $59.00 | -$0.01 |
|
8 | $13.36 | $13.40 | $0.04 |
|
9 | $121.50 | $147.74 | $26.24 |
|
10 | $49.14 | $49.14 | $0.00 |
|
11 | $12.62 | $12.55 | -$0.07 |
|
12 |
| $150.63 |
|
|
13 |
| $165.00 |
|
|
14 | $11.80 | $12.40 | $0.60 |
|
15 | $49.13 | $57.09 | $7.96 |
|
APE <$25: +/- 20% variance to RATE |
APE $25 - $100: +/- $5M variance to RATE |
APE >$100: +/- $20M variance to RATE |
Traffic Light Conditions:
if RATE <25 AND CostDiff >(RATE*.2) = Yellow, OR CostDiff <(RATE*.2) = Green
if RATE between 25-100 AND CostDiff is >5 = Yellow, else <5 = Green
if RATE <100 AND CostDiff >20 = Yellow, else <20 = Green
I've already calculated the difference between the RATE and the APE (CostDiff); now I need to take that difference and apply the variance allowed based on the APE, and have the CostHealth column return Green or Yellow to feed my traffic light. I believe my pseudo code for the traffic light conditions is correct, but cannot test that assumption.
- Anonymous2 years ago
Hi rosamhernandez1 ,
We can add two conditional columns.
Then we add three custom columns.
Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi rosamhernandez1 ,
Based on your description, we can create three columns.
CostHealth = SWITCH(TRUE(), [RATE]<25 && [CostDiff]>[RATE]*2,"Yellow", [CostDiff]<[RATE]*2,"Green", [RATE]>=25 && [RATE]<=100 && [CostDiff] >5,"Yellow", [CostDiff]<5,"Green", [RATE]<100 && [CostDiff]>20,"Yellow", [CostDiff] <20,"Green")variance_max = SWITCH(TRUE(), [APE]<25,[RATE]+ [RATE] * 0.2, [APE] >=25 && [APE]<=100,[RATE]+5, [APE]>100,[RATE]+20)variance_min = SWITCH(TRUE(), [APE]<25,[RATE]- [RATE] * 0.2, [APE] >=25 && [APE]<=100,[RATE]-5, [APE]>100,[RATE]-20)Then the result is as follows.
If I have misinterpreted your needs, please clarify in a follow-up response, preferably with an example of your desired outcome.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- rosamhernandez1
Helper I
thank you, I am not familiar with DAX and have been using M query to add columns as of now, is there a way to translate this into M?
- AnonymousNot applicable
Hi rosamhernandez1 ,
We can add two conditional columns.
Then we add three custom columns.
Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.