cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
MiloPowerBI
Frequent Visitor

DAX IF Statement to compare % difference between two values and return TEXT

Hello all, 

 

Hopefully a quick one for someone out there. 

PerformToPlan.png

 I have some data, like the image above where there is a list of materials, a Plan of what we planned to produce and Actual for what we actually produced. The numbers for Plan and Actual come from two different tables that are linked together in a relationship via the Material. 

 

What I want to be able to do is have a measure for the Perform to Plan column, where if the Actual is within 10% of the Plan (can be 10% over or 10% under) it returns "Hit", otherwise "Miss".

 

Additionally, I would then like to be able to build a few visualisations based on the number of Hits and Misses, so I dont know if a Measure or a Summarized Table is the best way for me to go. 

 

Any tips or advice, I would be very grateful. 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @MiloPowerBI ,

According to your description, here's my solution.

Create a calculated column in the Plan table.

Perform to plan =
IF (
    ABS ( DIVIDE ( RELATED ( 'Actual'[Actual] ) - 'Plan'[Plan], 'Plan'[Plan] ) ) <= 0.1,
    "Hit",
    "Miss"
)

Result:

vyanjiangmsft_1-1684394826260.png

 

If you want a visual to show the number of the misses and hits, put the Perform to plan in a column chart both in X-axis and Y-axis, and select count in the Y-axis, get the result:

vyanjiangmsft_2-1684394905014.png

I attach my sample below for your reference.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best regards,

Community Support Team_yanjiang

View solution in original post

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @MiloPowerBI ,

According to your description, here's my solution.

Create a calculated column in the Plan table.

Perform to plan =
IF (
    ABS ( DIVIDE ( RELATED ( 'Actual'[Actual] ) - 'Plan'[Plan], 'Plan'[Plan] ) ) <= 0.1,
    "Hit",
    "Miss"
)

Result:

vyanjiangmsft_1-1684394826260.png

 

If you want a visual to show the number of the misses and hits, put the Perform to plan in a column chart both in X-axis and Y-axis, and select count in the Y-axis, get the result:

vyanjiangmsft_2-1684394905014.png

I attach my sample below for your reference.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best regards,

Community Support Team_yanjiang

Hello yanjiang, 

 

That worked perfectly. Thank you. 

amitchandak
Super User
Super User

@MiloPowerBI , If Plan and actual need to be a measure. you need a new measure like

 

if([Actual]<[Plan], "Miss", "Hit")

 

Now if you hit hand miss in the slicer or on axis, You need to do dynamic segmentation with independent table

 

refer this video for process

Customer Retention with Dynamic Segmentation, New/Lost/Retain Customer Count: https://youtu.be/EyL7KMw877Q

Hello amitchandak, 

 

Thank you for your response, and that video did help me understand a bit better. 

 

However, the measure you proposed [if([Actual]<[Plan], "Miss", "Hit")] doesnt quite fit the bill. This will only return a Miss if the Actual is less than the Plan and a Hit if the Actual is more than the Plan. I'm looking to do something like if the Actual is within 10% of the Plan - higher OR lower - its a Hit. 

 

If the Plan is 100 and the Actual is 98, I would want this to return as a Hit, the measure you proposed would return a Miss for this. 

 

Any further advice?

 

Thank you. 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors