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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to compare two values in different columns and different rows, related to an ID

I'm starting to learn Power BI and metrics with DAX and some help will be apreciated, please. I would need to know how, in a sorted table (by ID, Modification and Date), of data already defined by fields ([ID, Modification, Fecha(=Date), V_INICIAL, V_FINAL, RESULT]), I can compare values ​​of different rows and columns, regardless of the number of iterations. My objective is to calculate a measure that returns the Number of different IDs per type of Modification, which meet the "OK" Result. This result compares, for each value of the Modification field, the value of the V_INITIAL of the first iteration, with the value of the V_FINAL of the last iteration, of the Modification. And if both values ​​are different, the Result is "OK", since the modification has been made. Otherwise it is "NOT_OK" because there is no modification. Thank you very much for help! 😉

TABLE.JPG

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

HI @Anonymous,

It sounds like a common value compares operation between start, end date based on category groups. If this is a case, you can refer to the following measure formula to extract the first and last value based on current category group.

Measure =
VAR filtered =
    CALCULATETABLE (
        table,
        ALLSELECTED ( table ),
        VALUES ( table[ID] ),
        VALUES ( table[Modification] )
    )
VAR _first =
    MINX ( filtered, [Fecha] )
VAR _last =
    MAXX ( filtered, [Fecha] )
RETURN
    IF (
        MINX ( FILTER ( filtered, [Fecha] = _first ), [V_INICIAL] )
            = MAXX ( FILTER ( filtered, [Fecha] = _last ), [V_FINAL] ),
        "NOT_OK",
        "OK"
    )

Regards,

Xiaoxin Sheng

View solution in original post

Anonymous
Not applicable

Thanks a lot, Xiaoxin.

It's working properly but worse the performance when i'm including the MEASURE into another one:

MEASURE_2 = CALCULATE(DISTINCTCOUNT('Table'[Id]),OR('Table'[Modification]="BACKUP",'TABLE'[Modification]="VARIABLE"),FILTER(Table,[MEASURE]="OK"),USERELATIONSHIP(Table[Fecha],'Date'[Date]))

When I use the MEASURE_2 in a dashboard, the charge is very slow. Sure, maybe I'm doing something wrong, using your MEASURE as a filter.

 

 

 

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @Anonymous,

It sounds like a common value compares operation between start, end date based on category groups. If this is a case, you can refer to the following measure formula to extract the first and last value based on current category group.

Measure =
VAR filtered =
    CALCULATETABLE (
        table,
        ALLSELECTED ( table ),
        VALUES ( table[ID] ),
        VALUES ( table[Modification] )
    )
VAR _first =
    MINX ( filtered, [Fecha] )
VAR _last =
    MAXX ( filtered, [Fecha] )
RETURN
    IF (
        MINX ( FILTER ( filtered, [Fecha] = _first ), [V_INICIAL] )
            = MAXX ( FILTER ( filtered, [Fecha] = _last ), [V_FINAL] ),
        "NOT_OK",
        "OK"
    )

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Thanks a lot, Xiaoxin.

It's working properly but worse the performance when i'm including the MEASURE into another one:

MEASURE_2 = CALCULATE(DISTINCTCOUNT('Table'[Id]),OR('Table'[Modification]="BACKUP",'TABLE'[Modification]="VARIABLE"),FILTER(Table,[MEASURE]="OK"),USERELATIONSHIP(Table[Fecha],'Date'[Date]))

When I use the MEASURE_2 in a dashboard, the charge is very slow. Sure, maybe I'm doing something wrong, using your MEASURE as a filter.

 

 

 

 

 

amitchandak
Super User
Super User

@Anonymous , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors