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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
RaineJ
Frequent Visitor

MATCH THE DATA FROM ONE COLUMN TO ANY OF THE DATA IN ANOTHER COLUMN IN ONE TABLE

Y.png

Ive been trying to do this logic where if the age match any of the value in the first column it will result the respective value in the second up to seventh column.

 

Ive been trying this code

Status =
    IF('Measure'[AGE]='Measure'[AIM]&&'Measure'[WEIGHT]<='Measure'[SUW_G],"SUW",
    IF('Measure'[AGE]='Measure'[AIM]&&'Measure'[WEIGHT]>='Measure'[UW+_G] || 'Measure'[WEIGHT] <= 'Measure'[UW-_G],"UW",
    IF('Measure'[AGE]='Measure'[AIM]&&'Measure'[WEIGHT]<='Measure'[N+_G] || 'Measure'[WEIGHT] <= 'Measure'[N-_G],"N",
    IF('Measure'[AGE]='Measure'[AIM]&&'Measure'[WEIGHT]>='Measure'[OW_G],"OW"
    ))))
 
the problem is example if the first cell in 2 different column matched thats when it will only show the right result.
 
Is there any way or condition where wherever I type the number as long as that number is available in the first cell it will result the right value?

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @RaineJ 
To be honest, I'm not sure if I correctly understand the requirement. However, this is a rather complex solution for you to check from your end. Please refer to attached sample file.

1.png

Status = 
VAR CurrentTable = 
    SELECTCOLUMNS ( 
        FILTER ( 'Table', 'Table'[AIM] = EARLIER ( 'Table'[AGE] ) ), 
        "SUW", [SUW_G], "UW",  [UW+_G], "UW-", [UW-_G], "N", [N+_G], "N-", [N-_G], "OGW", [OW_G], "AGE", [AGE] 
    )
VAR String1 = TOCSV ( CurrentTable, 1 )
VAR Items1 = SUBSTITUTE ( String1, UNICHAR ( 10 ), "|" )
VAR String2 = PATHITEM ( Items1, 1 )
VAR Items2 = SUBSTITUTE ( String2, ",", "|" )
VAR Length = COALESCE ( PATHLENGTH ( Items2 ), 1 )
VAR String3 = PATHITEM ( Items1, 2 )
VAR Items3 = SUBSTITUTE ( String3, ",", "|" )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = ADDCOLUMNS ( T1, "@Name", PATHITEM ( Items2, [Value] ), "@Value", VALUE ( PATHITEM ( Items3, [Value] ) ) )
VAR T3 = FILTER ( T2, [@Value] = 'Table'[WEIGHT] )
VAR ColumnName = SUBSTITUTE ( MAXX ( T3, [@Name] ), "-", "" )
VAR Result = SUBSTITUTE ( SUBSTITUTE ( ColumnName, "[", "" ), "]", "" )
RETURN
    Result

View solution in original post

12 REPLIES 12
tamerj1
Super User
Super User

Hi @RaineJ 
To be honest, I'm not sure if I correctly understand the requirement. However, this is a rather complex solution for you to check from your end. Please refer to attached sample file.

1.png

Status = 
VAR CurrentTable = 
    SELECTCOLUMNS ( 
        FILTER ( 'Table', 'Table'[AIM] = EARLIER ( 'Table'[AGE] ) ), 
        "SUW", [SUW_G], "UW",  [UW+_G], "UW-", [UW-_G], "N", [N+_G], "N-", [N-_G], "OGW", [OW_G], "AGE", [AGE] 
    )
VAR String1 = TOCSV ( CurrentTable, 1 )
VAR Items1 = SUBSTITUTE ( String1, UNICHAR ( 10 ), "|" )
VAR String2 = PATHITEM ( Items1, 1 )
VAR Items2 = SUBSTITUTE ( String2, ",", "|" )
VAR Length = COALESCE ( PATHLENGTH ( Items2 ), 1 )
VAR String3 = PATHITEM ( Items1, 2 )
VAR Items3 = SUBSTITUTE ( String3, ",", "|" )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = ADDCOLUMNS ( T1, "@Name", PATHITEM ( Items2, [Value] ), "@Value", VALUE ( PATHITEM ( Items3, [Value] ) ) )
VAR T3 = FILTER ( T2, [@Value] = 'Table'[WEIGHT] )
VAR ColumnName = SUBSTITUTE ( MAXX ( T3, [@Name] ), "-", "" )
VAR Result = SUBSTITUTE ( SUBSTITUTE ( ColumnName, "[", "" ), "]", "" )
RETURN
    Result

Thank you sir it already works for me. i just got confused with my data.

 

thank you sir but it dont work for me when i input different age.

@RaineJ 

Would you please explain further? What do you by input different age?

My bad sir. As I tried your code I only got the correct prediction in 0 but when I input different age like 1,2 55,56, and 60. It didnt show any prediction.

 

RaineJ_0-1676516228173.png

 

@RaineJ 

As you can see in my sample file I have used 3 different values for the AGE column and it worked just fine. Therefore I believe I don't fully understand the logic. Can we connect now via teams or zoom perhaps to clarify further?

wdx223_Daniel
Super User
Super User

Status =
    IF('Measure'[AGE]='Measure'[AIM],SWITCH(TRUE(),'Measure'[WEIGHT]<='Measure'[SUW_G],"SUW",'Measure'[WEIGHT]>='Measure'[UW+_G] && 'Measure'[WEIGHT] <= 'Measure'[UW-_G],"UW",'Measure'[WEIGHT]<='Measure'[N+_G]&&'Measure'[WEIGHT] <= 'Measure'[N-_G],"N",
    'Measure'[WEIGHT]>='Measure'[OW_G],"OW"
    ))

Thank you, but i still have the same problem.
 it only show result if the cell in the same row matched

RaineJ_0-1676447237391.png

 

Status =
VAR _tbl=FILTER('Measure','Measure'[AGE]=EARLIER('Measure'[AIM]))
RETURN
    SWITCH(TRUE(),'Measure'[WEIGHT]<=MAXX(_tbl,'Measure'[SUW_G]),"SUW",'Measure'[WEIGHT]>=MAXX(_tbl,'Measure'[UW+_G]) && 'Measure'[WEIGHT] <= MAXX(_tbl,'Measure'[UW-_G]),"UW",'Measure'[WEIGHT]<=MAXX(_tbl,'Measure'[N+_G])&&MAXX(_tbl,'Measure'[WEIGHT]) <= 'Measure'[N-_G],"N",
    'Measure'[WEIGHT]>=MAXX(_tbl,'Measure'[OW_G]),"OW"
    )

im really thankful sir. but it is still the same in my case. 

the first row only got the right prediction while the rest, output the "OW".

im a beginner with this so im wondering if its possible.

Status =
VAR _tbl =
    FILTER ( 'Measure', 'Measure'[AGE] = EARLIER ( 'Measure'[AIM] ) )
RETURN
    SWITCH (
        TRUE (),
        'Measure'[WEIGHT] <= MAXX ( _tbl, 'Measure'[SUW_G] ), "SUW",
        'Measure'[WEIGHT] >= MAXX ( _tbl, 'Measure'[UW+_G] )
            && 'Measure'[WEIGHT] <= MAXX ( _tbl, 'Measure'[UW-_G] ), "UW",
        'Measure'[WEIGHT] <= MAXX ( _tbl, 'Measure'[N+_G] )
            && MAXX ( _tbl, 'Measure'[WEIGHT] ) <= 'Measure'[N-_G], "N",
        'Measure'[WEIGHT] >= MAXX ( _tbl, 'Measure'[OW_G] ), "OW"
    )

i got a wrong filter condition

the result still the same sir.

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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