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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
caruso1058
Microsoft Employee
Microsoft 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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

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





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





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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.

Users online (2,717)