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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Regular Visitor

## 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.

1 ACCEPTED SOLUTION
Community Support

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 4
Community Support

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.

Regular Visitor

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?

Community Support

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.

Regular Visitor
thank you! this did the trick, much appreciated!

## Helpful resources

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors