Forum Discussion

JamesLeach's avatar
JamesLeach
Frequent Visitor
7 years ago
Solved

Calculated column or measure? Data from specific row for all rows matching value in another column.

Hello everyone!  

 

I've got a data set similar to this (without the 'UniqueId' column - that's what I'm trying to add).

 

RecordDataValueUniqueId
1UniqueId10011001
1ThomasBoise1001
1Sales2915.351001
1Range-25%1001
2CoryJackson1002
2VincentCharleston1002
2RegionPNW1002
2UniqueId10021002
3UniqueId10011001
3VictorCheyenne1001
3Retired$true1001
4UniqueId10031003
4JustinSalt Lake City1003
5UniqueId10011001
5BrandonDes Moines1001
5PeterSacramento1001
5JoelBaton Rouge1001
5Range44%1001
6JacobHartford1002
6UniqueId10021002
6NotesDiscontinued1002
7Managercc26-4f081004
7DerekAtlanta1004
7UniqueId10041004

 

Each 'Record' will have a 'UniqueId' which I would like to add to each row.  I've done similar things with DAX, using CALCULATE and FILTER, but am having difficulity figuring this one out.   

 

Does anyone have any suggestions? 

  • As a calculated column, you could do this:

     

    UniqueID = 
    VAR __table = FILTER(ALL('Table2'),[Record]=EARLIER([Record]) && [Data]="UniqueId")
    RETURN
    MAXX(__table,[Value])

    As a measure, it would be:

     

    mUniqueID = 
    VAR __record = MAX([Record])
    VAR __table = FILTER(ALL('Table2'),[Record]=__record && [Data]="UniqueId")
    RETURN
    MAXX(__table,[Value])

    Assuming you put it in a visualization with at least Record.

3 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    As a calculated column, you could do this:

     

    UniqueID = 
    VAR __table = FILTER(ALL('Table2'),[Record]=EARLIER([Record]) && [Data]="UniqueId")
    RETURN
    MAXX(__table,[Value])

    As a measure, it would be:

     

    mUniqueID = 
    VAR __record = MAX([Record])
    VAR __table = FILTER(ALL('Table2'),[Record]=__record && [Data]="UniqueId")
    RETURN
    MAXX(__table,[Value])

    Assuming you put it in a visualization with at least Record.

    • JamesLeach's avatar
      JamesLeach
      Frequent Visitor

      Great, thank you!  

       

      That's exactly what I was looking for.   

       

      I really appreaciate your help.