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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

For 0 and Blank value matching returns the true value but want to consider false.

I have used an if formula to matches the values from two different columns and want to return "Y" and "N" based on matched value but for 0 and blank it is showing "Y" that means matched but I it should be "N" since 0 and blank is not matching. I have attached the screenshot and DAX code.

 

Looking for expert suggetions and opinions.

 

DAX - 

Matched 1 = IF(SUM('New Data Table'[Amount]) = SUM('New Data Table'[General_Ledger_Entries.Amount]), "Y", "N")
 
*** Here, the row no. 2 is showing "Y" but it is not matched since the value is 0 and blank.
 
Capture.PNG
 
Thanks!
 
 
1 ACCEPTED SOLUTION
sebastiandyrby
Resolver I
Resolver I

Hi

You need to take into account that the blanks are being treated as zeros in your comparions. One way to do it is with the ISBLANK() function. A solution could be a calculated column like this:

 

Matched 1 = 
VAR blank1 = IF(ISBLANK('Table'[System 1]),1)
VAR blank2 = IF(ISBLANK('Table'[System 2]),1)

VAR _comparison = 
SWITCH(
    TRUE(),
    blank1+blank2 = 2, "Y",
    blank1+blank2 = 1, "N",
    'Table'[System 1]='Table'[System 2], "Y",
    'Table'[System 1]<>'Table'[System 2], "N"
)

RETURN _comparison

 

Here, I create two variables that check if each column is blank and returns a 1 if that is the case. Then I use SWITCH to determine the comparisons: if both are blank they are similar ("Y"), if only one is blank they are different ("N"), and if there are no blanks they need to actually be compared. This returns:

sebastiandyrby_0-1677055932186.png

Hope this helps!

View solution in original post

2 REPLIES 2
sebastiandyrby
Resolver I
Resolver I

Hi

You need to take into account that the blanks are being treated as zeros in your comparions. One way to do it is with the ISBLANK() function. A solution could be a calculated column like this:

 

Matched 1 = 
VAR blank1 = IF(ISBLANK('Table'[System 1]),1)
VAR blank2 = IF(ISBLANK('Table'[System 2]),1)

VAR _comparison = 
SWITCH(
    TRUE(),
    blank1+blank2 = 2, "Y",
    blank1+blank2 = 1, "N",
    'Table'[System 1]='Table'[System 2], "Y",
    'Table'[System 1]<>'Table'[System 2], "N"
)

RETURN _comparison

 

Here, I create two variables that check if each column is blank and returns a 1 if that is the case. Then I use SWITCH to determine the comparisons: if both are blank they are similar ("Y"), if only one is blank they are different ("N"), and if there are no blanks they need to actually be compared. This returns:

sebastiandyrby_0-1677055932186.png

Hope this helps!

Anonymous
Not applicable

Thank you so much. It worked for me and marked it as solution.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.