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

Reply
rosamhernandez1
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

Hi @rosamhernandez1 ,

 

We can add two conditional columns.

vtangjiemsft_0-1714962834600.png

vtangjiemsft_1-1714962848566.png

 

Then we add three custom columns.

vtangjiemsft_2-1714963157529.png

vtangjiemsft_3-1714963171234.png

vtangjiemsft_4-1714963189241.png

 

Then the result is as follows.

vtangjiemsft_5-1714963238002.png

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. 

View solution in original post

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

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.

vtangjiemsft_0-1714355769540.png

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. 

 

@v-tangjie-msft

 

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?

Hi @rosamhernandez1 ,

 

We can add two conditional columns.

vtangjiemsft_0-1714962834600.png

vtangjiemsft_1-1714962848566.png

 

Then we add three custom columns.

vtangjiemsft_2-1714963157529.png

vtangjiemsft_3-1714963171234.png

vtangjiemsft_4-1714963189241.png

 

Then the result is as follows.

vtangjiemsft_5-1714963238002.png

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. 

@v-tangjie-msft thank you! this did the trick, much appreciated!

Helpful resources

Announcements
Europe Fabric Conference

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 Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

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