Forum Discussion

caruso1058's avatar
caruso1058
Microsoft Employee
6 years ago
Solved

Searching a Column to Return Value

Hello I have a a Table with several iterations of part numbers.
If a part is still in development then I need to return the latest part number. 

If the part is no longer in Development then return "Production" 

 

Here is what my Data looks like:

 

Part NumberPN_BasePN_SuffixCount_of_PN_Bases
Q1234-900Q12349005
Q1234-901Q12349015
Q1234-902Q12349025
Q1234-903Q12349035
Q1234-001Q12340015
Q9876-900Q98769003
Q9876-901Q98769013
Q9876-001Q98760013
Q5678-900Q56789002
Q5678-901Q56789012

 

I would like to create a calculated column or two to determine the latest version of a Part and its current state such as this:

 

Part NumberPN_BasePN_SuffixCount_of_PN_BasesCurrent_VersionState
Q1234-900Q12349005FALSEDevelopment
Q1234-901Q12349015FALSEDevelopment
Q1234-902Q12349025FALSEDevelopment
Q1234-903Q12349035FALSEDevelopment
Q1234-001Q12340015TRUEProduction
Q9876-900Q98769003FALSEDevelopment
Q9876-901Q98769013FALSEDevelopment
Q9876-001Q98760013TRUEProduction
Q5678-900Q56789002FALSEDevelopment
Q5678-901Q56789012TRUEDevelopment
  • This is one way to do this in a calculated column expression. Note that you can choose to return any of the last 3 variables for different results (for example, the latest version, Dev vs Prod, or It's the last T or F).

    Latest Version =
    VAR thisversion = Parts[PN_Suffix]
    VAR latestproduction =
        CALCULATE (
            MAX ( Parts[PN_Suffix] ),
            ALLEXCEPT ( Parts, Parts[PN_Base] ),
            FILTER ( ALL ( Parts[PN_Suffix] ), VALUE ( Parts[PN_Suffix] ) < 900 )
        )
    VAR latestdev =
        CALCULATE (
            MAX ( Parts[PN_Suffix] ),
            ALLEXCEPT ( Parts, Parts[PN_Base] ),
            FILTER ( ALL ( Parts[PN_Suffix] ), VALUE ( Parts[PN_Suffix] ) > 900 )
        )
    VAR latest =
        IF ( ISBLANK ( latestproduction ), latestdev, latestproduction )
    VAR islatest = thisversion = latest
    VAR prodordev =
        IF ( ISBLANK ( latestproduction ), "Development", "Production" )
    RETURN
        latest

    If this works for you, mark it as the solution. Praise is also appreciated. Please let me know if you don't.

    Best regards

    Pat

4 Replies

    • caruso1058's avatar
      caruso1058
      Microsoft Employee

      Hello amitchandak ,

       

      I might be able to bring in the date values with a another query from the main data source.  If I am able to bring in the date value then would the Calculated Column look like this:

       

      IF([DATE] = MAXX(FILTER(table,[PN_Base]=EARLIER([PN_Base])),[DATE]),"Production", "Development")  ?


      Thank you for your help with this!

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    This is one way to do this in a calculated column expression. Note that you can choose to return any of the last 3 variables for different results (for example, the latest version, Dev vs Prod, or It's the last T or F).

    Latest Version =
    VAR thisversion = Parts[PN_Suffix]
    VAR latestproduction =
        CALCULATE (
            MAX ( Parts[PN_Suffix] ),
            ALLEXCEPT ( Parts, Parts[PN_Base] ),
            FILTER ( ALL ( Parts[PN_Suffix] ), VALUE ( Parts[PN_Suffix] ) < 900 )
        )
    VAR latestdev =
        CALCULATE (
            MAX ( Parts[PN_Suffix] ),
            ALLEXCEPT ( Parts, Parts[PN_Base] ),
            FILTER ( ALL ( Parts[PN_Suffix] ), VALUE ( Parts[PN_Suffix] ) > 900 )
        )
    VAR latest =
        IF ( ISBLANK ( latestproduction ), latestdev, latestproduction )
    VAR islatest = thisversion = latest
    VAR prodordev =
        IF ( ISBLANK ( latestproduction ), "Development", "Production" )
    RETURN
        latest

    If this works for you, mark it as the solution. Praise is also appreciated. Please let me know if you don't.

    Best regards

    Pat

    • caruso1058's avatar
      caruso1058
      Microsoft Employee

      Wow mahoneypat ,

       

      This is beautiful and works perfectly. I can only hope that my skills are as a savy as this one day!

       

      Thanks a bunch!