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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
caruso1058
Employee
Employee

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
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@caruso1058 , do you date column. Because all these columns will not lead to max mix etc.

as of now create index column

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

and try like

if([Index] = maxx(filter(table,[PN_Base]=earlier([PN_Base])),[index]),"Production", "Development")

 

The ideal would be a date. in place of index , as index it orde rin which got data in power bi

View solution in original post

mahoneypat
Employee
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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Employee
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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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!

amitchandak
Super User
Super User

@caruso1058 , do you date column. Because all these columns will not lead to max mix etc.

as of now create index column

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

and try like

if([Index] = maxx(filter(table,[PN_Base]=earlier([PN_Base])),[index]),"Production", "Development")

 

The ideal would be a date. in place of index , as index it orde rin which got data in power bi

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!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.