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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Getting an IF statement to work

Hi everyone,

 

I am trying to show when a product is sold above or below the Price per Unit.  For example if a product is sold for $10 and the minimum is $8, the IF statement should return Above.  And if a product is being sold for $6 and the minimum is $8 the IF statement should return Below.  I tried using this dax formula but when I put it into the table it removes values from the Price per Unit column and the Lowest Price column.  It also seems to add products that have already been filtered out back into the table when adding the Y/N measure.  Not sure if it would create an issue but the Lowest price measure pulls from a different dataset but are connected through relationship.

 

These are the DAX formulas I've created.

Price per Unit = DIVIDE('Measures (2)'[Sum20-21],'Measures (2)'[SumSingleUnits])
Lowest Price = SUM('Unit Price'[Price])
Y/N = IF([Price per Unit] < [Lowest Price], "Below","Above")

 

The rows that have $15 should be Above and the rows that are $0.01 should be Below

johnw597_0-1638993273500.png

With the added Y/N measure

johnw597_1-1638994970969.png

Thank you for the help!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous sorry missed the comma (,) after TRUE

 

Y/N =
VAR __priceperUnit = [Price Per Unit]
VAR __lowestprice = [Lowest Price]
RETURN
SWITCH ( TRUE(),
  __priceperUnit == BLANK() || __lowerprice == BLANK(), BLANK(),
  __priceperUnit < __lowestprice, "Below",
  "Above"
)

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@Anonymous that shouldn't matter if there is a common dimension between these two tables. Not sure how the data model is setup



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k  hmmm weird.  I thought I had created the relationship the right way I'll have to do some more digging around in the data.  Thanks for the help!

parry2k
Super User
Super User

@Anonymous sorry missed the comma (,) after TRUE

 

Y/N =
VAR __priceperUnit = [Price Per Unit]
VAR __lowestprice = [Lowest Price]
RETURN
SWITCH ( TRUE(),
  __priceperUnit == BLANK() || __lowerprice == BLANK(), BLANK(),
  __priceperUnit < __lowestprice, "Below",
  "Above"
)

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi again @parry2k ,

 

I think I may have spoke too soon 😅.  It looks like it is just the Below part that isn't quite matching up.  Would the issue casuing this be because data is coming from two different data sources? Thank you for the help!

johnw597_1-1639000112713.png

Anonymous
Not applicable

Hi @parry2k ,

 

That worked perfectly!  Thank you so much for the help!

parry2k
Super User
Super User

@Anonymous try this, you need to check blank()

 

Y/N =
VAR __priceperUnit = [Price Per Unit]
VAR __lowestprice = [Lowest Price]
RETURN
SWITCH ( TRUE()
  __priceperUnit == BLANK() || __lowerprice == BLANK(), BLANK(),
  __priceperUnit < __lowestprice, "Below",
  "Above"
)

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k ,

 

I am trying to use your formula but it is throwing a syntax error on the __priceperUnit in row 6.  I'm not quite sure what I'm missing or why its not working.  I tried renaming it but no luck there.  Thank you for the help!

johnw597_0-1638998838968.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.