Forum Discussion

DsIshukone's avatar
DsIshukone
Frequent Visitor
2 years ago
Solved

Select values and return corresponding values associated within group of selected values

Hi community,

 

I'm now facing a quite tricky situation that I will need help from you experts, so here's the situation:

 

I have a dataset, in this dataset there's ID, Long for longitude, Lat for Latitude, Pix (a coordinate in Lambert Conformal Conic format, it has 2 parts, one for x and one for y), and Score. Records with different Long and Lat will be grouped into the same Pix (e.g., Records 1 to 5 with same Pix x10000_y10000, even though their Long and Lat are totally different, Records 6 to 8 with same Pix x10800_y10000).

 

What I want to achieve, for examle if I select Pix equals x10800_y10000 (which is records 6 to 8), the results will return records 6 to 8, as well as records 1 to 5.

 

Let me explain, by selecting Pix x10800_y10000, I want to return all records based on 2 conditions:

1. whose Pix for x is within 1000 of 10800, meaning Pix for x is between 9800 and 11800; 

2. whose Pix for y is within 1000 of 10000, meaning Pix for y is between 9000 and 11000

 

So here, for records 1 to 5, their Pix is x10000_y10000, so the Pix for x is 10000, which is between 9800 and 11800; the Pix for y is 10000, also between 9000 and 11000, both conditions met, thus records 1 to 5 will be returned, along with records 6 to 8. Other records will not be returned, because at least 1 condition is not met.

 

Thank you in advance!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi DsIshukone 

     

    For your question, here is the method I provided:

     

    Since, you need to transform the data. In order to present the data, I would suggest you to duplicate an identical table and create a relationship based on the ID column.

     

     

    Enter the power query screen.

     

    Select the Pix column and click Split Column by Delimiter in Transform.

     

     

     

     

    Select the Pix.1 column and click Split Column by Positions in Transform.

     

     

     

    Select the Pix.1.1 and Pix.1.2 columns and click Pivot Column in Transform.

     

     

     

     

    Do the same for Pix.2. You will get data like this:

     

     

    Close & Apply.

     

     

    Create a measure.

     

    _ID = 
    IF(
        SELECTEDVALUE('Copy Table'[x]) <= 10800 
        && 
        SELECTEDVALUE('Copy Table'[y]) <= 10000, 
        CALCULATE(SELECTEDVALUE('Copy Table'[ID])), 
        BLANK()
    )

     

    Here is the result.

     

     

    Regards,

    Nono Chen

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

     

     

     

     

     

     

     

     

     

     

2 Replies

  • DsIshukone's avatar
    DsIshukone
    Frequent Visitor

    Sample dataset looks like:

    IDLongLatPixScore
    11010x10000_y10000123
    21011x10000_y10000456
    31012x10000_y10000789
    41111x10000_y10000321
    51211x10000_y10000654
    62020x10800_y100001121
    72021x10800_y100001123
    82121x10800_y100001125
    93030x11900_y106004022
    103031x11900_y106004025
    113032x11900_y106004028
    123130x11900_y106004029
    134040x20000_y10000305
    144041x20000_y10000306
    154042x20000_y10000307
    164142x20000_y10000308

     

    What I want it returns upon selecting Pix equals x10800_y10000:

    IDLongLatPixScore
    11010x10000_y10000123
    21011x10000_y10000456
    31012x10000_y10000789
    41111x10000_y10000321
    51211x10000_y10000654
    62020x10800_y100001121
    72021x10800_y100001123
    82121x10800_y100001125
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi DsIshukone 

     

    For your question, here is the method I provided:

     

    Since, you need to transform the data. In order to present the data, I would suggest you to duplicate an identical table and create a relationship based on the ID column.

     

     

    Enter the power query screen.

     

    Select the Pix column and click Split Column by Delimiter in Transform.

     

     

     

     

    Select the Pix.1 column and click Split Column by Positions in Transform.

     

     

     

    Select the Pix.1.1 and Pix.1.2 columns and click Pivot Column in Transform.

     

     

     

     

    Do the same for Pix.2. You will get data like this:

     

     

    Close & Apply.

     

     

    Create a measure.

     

    _ID = 
    IF(
        SELECTEDVALUE('Copy Table'[x]) <= 10800 
        && 
        SELECTEDVALUE('Copy Table'[y]) <= 10000, 
        CALCULATE(SELECTEDVALUE('Copy Table'[ID])), 
        BLANK()
    )

     

    Here is the result.

     

     

    Regards,

    Nono Chen

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