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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
elif
Frequent Visitor

if statement with the value

Hello everyone,

 

There are some products called "NPI" but after the 4 years (not all the time) they need to be changed as a "Core Product" so when I need to see NPIs for the previous years, if they're still NPI I need to see them but if they expired this year I need to see them as Core Product but the previous years still have to be NPI.

 

  invoice date
ProductNPI End Date201820192020
A2018$1,000  
B2019$5,000$3,000 
C2022$2,000$3,000$5,000

 

I tried to write a DAX measurement to calculate these changes and I want to use the result in the IF statement but that's not working correctly but the measurement does.

 

If the value is 1 the output has to be "NPI' if it is not, get the value from 'Product'[POS type]  (which they're; Core Product, Custom, Identity Product, outofscope)

 

is grater = VAR maxtable1 = CALCULATE(MAX('Date'[Date])) VAR maxtable2 = CALCULATE(MAX('Product'[NPI End Date])) RETURN IF (maxtable2 >= maxtable1, 1,0)
 
POS Type New = IF( [is grater] = 1, "NPI", 'Product'[POS type])
 
elif_1-1645470370061.png

 

By the way, 'Product'[NPI End Date and 'Date'[Date] don't have an active relationship between the columns.

 

 

 

 

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

Hi, 

According to your description and sample pictures and screenshots, I can roughly understand where did your error occur. You are using the [is grater] as a measure in the table chart. But you are trying the create a calculated column [POS Type New] to get the value of the measure [is grater]. This may cause the value error in the calculated column [POS Type New].

vrobertqmsft_0-1645690917712.png

 

Therefore, I suggest you to create a new measure [POS Type New1] like this:

POS Type New1 = IF( [is grater] = 1, "NPI", MAX('Product'[POS type]))

 

Then you can use this measure to be placed into the table chart to replace the original [POS Type New] to check if the issue disappears.

 

And you can get what you want.

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

3 REPLIES 3
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description and sample pictures and screenshots, I can roughly understand where did your error occur. You are using the [is grater] as a measure in the table chart. But you are trying the create a calculated column [POS Type New] to get the value of the measure [is grater]. This may cause the value error in the calculated column [POS Type New].

vrobertqmsft_0-1645690917712.png

 

Therefore, I suggest you to create a new measure [POS Type New1] like this:

POS Type New1 = IF( [is grater] = 1, "NPI", MAX('Product'[POS type]))

 

Then you can use this measure to be placed into the table chart to replace the original [POS Type New] to check if the issue disappears.

 

And you can get what you want.

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

amitchandak
Super User
Super User

@elif , Try with this change

 

is grater = VAR maxtable1 = CALCULATE(MAXX(allselected('Date'), 'DAte'[Date]))
VAR maxtable2 = CALCULATE(MAX('Product'[NPI End Date]))
RETURN IF (maxtable2 >= maxtable1, 1,0)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you @amitchandak  but still not working for me. Actually, 'is grater' calculation works very well but when I put the result to the IF statement, I don't know why but it's not getting the right result. "1" should give me "NPI" and "0" should give me the 'Product'[POS type] column's outputs. (like Core Product, Custom etc.)

 

POS Type New = IF( [is grater] = 1, "NPI", 'Product'[POS type])

 

elif_0-1645500632165.png

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.