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

Comparing values of the same column followed by comparing with different column to create output.

bi.PNG

Hello,
I am trying to create a new column "Result".
The Result column is created based on this logic, compare value on B3 with value on B2, if it is the same then compare value on A3 with value on A2 if it is the same then the Result in C3 = 1. 
Next, compare value on B4 with value on B3, if it is the same then compare value on A4 with value on A3 if it is different then the Result in C4 = 2.
Finally, compare value on B5 with value on B4, if it is different then the Result in C5 = 3.

Thank you in advance.

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

hi, @Anonymous 

You could try this way:

Step1:

Add an index column in edit queries or use Rankx Function

Step2:

Use this formula to add a calculate column

Result = 
IF (
    'Table'[Index] = 1,
    "s",
    IF (
        CALCULATE (
            MAX ( 'Table'[Type] ),
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
        ) = 'Table'[Type],
        IF (
            CALCULATE (
                MAX ( 'Table'[Size] ),
                FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
            ) = 'Table'[Size],
            "1",
            "2"
        ),
        "3"
    )
)

Result:

6.JPG

here is a simple pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
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

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

You could try this way:

Step1:

Add an index column in edit queries or use Rankx Function

Step2:

Use this formula to add a calculate column

Result = 
IF (
    'Table'[Index] = 1,
    "s",
    IF (
        CALCULATE (
            MAX ( 'Table'[Type] ),
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
        ) = 'Table'[Type],
        IF (
            CALCULATE (
                MAX ( 'Table'[Size] ),
                FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
            ) = 'Table'[Size],
            "1",
            "2"
        ),
        "3"
    )
)

Result:

6.JPG

here is a simple pbix file, please try it.

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Is the data in any order? Can you rank them?

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.