Results 1 to 2 of 2

Thread: Extract unique value from column using DAX

  1. #1
    New Member
    Join Date
    Oct 2019
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Extract unique value from column using DAX

    I've come across what I thought should be a simple problem, but I can't quite figure it out. I have a table that's the result of an expression that could have a column like this in certain instances:

    Row Key Index
    AH4000 1
    AH4000 2
    AP9999 3

    What I want is to keep only rows with a unique row key so that I can get the correct single index value (the red value). Using distinct/values wouldn't help because it would still show the 1st or 2nd row in the table, where as I want those rows that contain a row key that exists in the table more than once to be fully excluded. I can't rely on position of the index because it varies, so I don't think min/max would work. I have this calculation as part of a complicated calculated column so there are memory concerns as well. Is there an easy answer to this that I'm missing?

    Thanks,
    Josh

  2. #2
    Board Regular
    Join Date
    Apr 2014
    Location
    Mitten State
    Posts
    234
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Extract unique value from column using DAX

    If I understand your question, you want your filter to exclude all rows where the row key appears more than once and to capture the index value. What about a COUNTROWS?
    Code:
    [Permitted Index] =VAR MyIndex = MyTable[Index]
    RETURN
        IF (
            CALCULATE (
                COUNTROWS ( MyTable[Row Key] ),
                FILTER ( ALL ( MyTable ), MyTable[Row Key] = EARLIER ( MyTable[Row Key] ) )
            ) > 1,
            BLANK (),
            MyIndex
        )
    Shame on me, I can't remember if the countrows returns the original row too (I think so). If not, you would have to set the test to > 0.
    Last edited by macfuller; Oct 18th, 2019 at 01:25 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •