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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX formula to compare 2 rows

Hi,

I have a table like the below and want to setup a calculated column with DAX to check whether each key from the "Concat" column has a value or not.

image.png

 

For example:

- po1drop1 has 2 rows, with 1 row has Value=100, so I want the Result=Yes

- podrop2 has 1 row only with blank value, so I want the Result=No

- podrop3 has 2 rows, with 1 row has Value=100, so I want the Result=Yes

- podrop4 has 2 rows, with 1 row has Value=100, so I want the Result=Yes

- podrop5 has 1 row only with blank value, so I want the Result=No

- podrop6 has 1 row only with blank value, so I want the Result=No

 

image.png

 

Not sure how to put the FILTER or EARLIER function in place in order to achieve the desired result.

Can anyone assist? Thanks.

 

Best regards,

Emily

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , Try a new column

 

if(sumx(filter(table,[concat]=earlier([concat])),[Value])=100 ,"Yes","No")

 

or

 

if(maxx(filter(table,[concat]=earlier([concat])),[Value])=100 ,"Yes","No")

View solution in original post

Hi @Anonymous ,

 

Glad that the solutions works for you.

Can you accept it as a solution so that others can refer it later?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

13 REPLIES 13
Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can create a calculated column using DAX as follows:

 

IfExists = var cnt = CALCULATE(DISTINCTCOUNTNOBLANK(Category[Value]), FILTER(Category, Category[Category] = EARLIER(Category[Category]))) return IF(cnt > 0, "Yes", "No")
 
It will give you following result:
cattest.png
In the above DAX, just use columns from your original data. I did this on a test data at my end.
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

@Pragati11  Thanks, I just tested your result in my file but I got the entire column with "Yes".....not sure if I did something wrong in the formula?

 

Best regards,

Emily

 

image.png

Hi @Anonymous ,

 

What's the datatype of your "VALUE" column? Is it wholenumber or text?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

@Pragati11  VALUE column is a STRING data type and some rows with blank data.

Hi @Anonymous ,

 

Not sure why it is not working at your end.

I have tried the same formula when VALUE column is a string or numeric, it works for me.

Can you check again as the DISTINCTCOUNTNOBLANK will work both for String and numeric columns?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

@Pragati11 Would you mind to share your PBIX file with the solution so that I can test it from my end? Thanks!

 

Best regards,

Emily

HI @Anonymous ,

 

There you go:

https://wetransfer.com/downloads/89da4806f8d3ab1ed2d37ad8b9abe26f20200714115411/08df214f8f1e1c720aa851341fe122ee20200714115431/e8f193

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

The proposed solution is working fine now, thank you very much! @Pragati11 @amitchandak 

 

Best regards,

Emily

Hi @Anonymous ,

 

Glad that the solutions works for you.

Can you accept it as a solution so that others can refer it later?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

amitchandak
Super User
Super User

@Anonymous , Try a new column

 

if(sumx(filter(table,[concat]=earlier([concat])),[Value])=100 ,"Yes","No")

 

or

 

if(maxx(filter(table,[concat]=earlier([concat])),[Value])=100 ,"Yes","No")

Anonymous
Not applicable

@amitchandak 

Sorry that I found out your proposed solution is not 100% working in my real enviroment, because the Value column is a string type rather than numerical type so I can't use SUMX or MAXX fuction.

Any other way to get the same result in considering the Value column is a string?

 

Best regards,

Emily

@Anonymous , Maxx will work for String. Do you want sum up value to check?'if it have only numeric that you can try [Value]*1

Anonymous
Not applicable

@amitchandak Thanks for your proposed solution and both formulas working well. Have a great day!

 

Best regards,

Emily

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors