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
helpme
Resolver I
Resolver I

Help with if statement for different values in other columns

I have a dataset below:

 

LocationNameageincome
UKxteenlow
UKxadultlow
UKyteenhigh
USAzadultlow
USAzadulthigh

 

I want to point out mistakes in the dataset where for one person ( ie x or z), the age or income columns are not the same (when they should be)

 

I want to end up with a table visual in powerbi whereby it points out the discrepancy 

 

LocationNameDiscrepancy found?
UKXY
UKYN
USAZY

 

What dax can i use to do this?

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

Hi @helpme ,

According to your description, here's my solution. Create a measure.

Discrepancy found? =
IF (
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Location] = MAX ( 'Table'[Location] )
                && 'Table'[Name] = MAX ( 'Table'[Name] )
                && (
                    'Table'[age] <> MAX ( 'Table'[age] )
                        || 'Table'[income] <> MAX ( 'Table'[income] )
                )
        )
    ) > 0,
    "Yes",
    "No"
)

Get the correct result:

vkalyjmsft_0-1670491978622.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

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

Hi @helpme ,

According to your description, here's my solution. Create a measure.

Discrepancy found? =
IF (
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            'Table'[Location] = MAX ( 'Table'[Location] )
                && 'Table'[Name] = MAX ( 'Table'[Name] )
                && (
                    'Table'[age] <> MAX ( 'Table'[age] )
                        || 'Table'[income] <> MAX ( 'Table'[income] )
                )
        )
    ) > 0,
    "Yes",
    "No"
)

Get the correct result:

vkalyjmsft_0-1670491978622.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

ddpl
Solution Sage
Solution Sage

@helpme ,

 

Create a Calculated Column as shown below...

 

Discrepancy =

IF (
    CALCULATE (
        COUNT ( 'Table'[income] ),
        FILTER (
            'Table',
            'Table'[Location] = EARLIER ( 'Table'[Location] )
                && 'Table'[Name] = EARLIER ( 'Table'[Name] )
        )
    ) > 1,
    IF (
        DISTINCTCOUNT ( 'Table'[age] ) > 1
            || DISTINCTCOUNT ( 'Table'[income] ) > 1,
        "Y"
    ),
    "N"
)

Hi ddpl,

 

Thanks for submitting this, unfortunately it doesn't work as it doesn't fulfil the requirement of being able to indicate which ones have the same location & name, but different values for income or age.

 

If it helps, there will only ever be "teen" or "adult" values for age, and with Income it will only be "High", Low" or "N/a"

@helpme ,

 

can you share slightly more data with expected result.

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.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.