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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
abrother
Frequent Visitor

Assign value to multiple rows based on rules and values from another column

Hi all,

 

I have a difficult challenge I'm trying to overcome (at least difficult for me) in that I'm trying to create a new column that assigns a value to a set of rows (serial numbers all from a single production lot #) based on evaluating values in another column. Here's the breakdown:

 

Each lot produces different SKUs depending on certain factors in production so we might have Lot 123ABC with S/Ns 123ABC-001, 002, and 003 being SKU 123456, while S/Ns 004-006 are a different SKU (456789). Each SKU has a value called a "sub-driver" that I have pulled over to my main table using LOOKUPVALUE, but for each Lot I need to assign an overall "Primary Driver" value which is based on looking at the "sub-driver".

 

For example, if Lot 123ABC has SKUs that contain sub-drivers SD1 and SD2, and the primary driver in this case is SD1 (this is based on rules), I need to assign the value "PD1" to all of the rows in that lot (all of the S/Ns).

 

Basically what I'm looking for is a way to search the relevant S/Ns associated with the overall Lot # and then assign the Primary Driver value to all of the S/Ns in that lot based on rules when looking at the "sub-driver" column. I've copied a simple version of what I'm talking about as an example below. In the sample the rules should be that for Lot 123ABC if the SD1 sub-driver is present, then the Primary Driver should be PD1, in Lot 234BCD if the SD3 sub-driver is present then the Primary Driver should be PD3.

 

Let me know if any additional clarification is needed. Thank you all very much in advance.

 

Lot #S/NSKUSub-DriverPrimary Driver
123ABC123ABC-001123456SD2PD1
123ABC123ABC-002123456SD2PD1
123ABC123ABC-003123456SD2PD1
123ABC123ABC-004456789SD1PD1
123ABC123ABC-005456789SD1PD1
123ABC123ABC-006456789SD1PD1
123ABC123ABC-007789012SD3PD1
123ABC123ABC-008789012SD3PD1
123ABC123ABC-009789012SD3PD1
123ABC123ABC-010234567SD1PD1
123ABC123ABC-011234567SD1PD1
123ABC123ABC-012234567SD1PD1
234BCD234BCD-001789012SD3PD3
234BCD234BCD-002789012SD3PD3
234BCD234BCD-003789012SD3PD3
234BCD234BCD-004123456SD2PD3
234BCD234BCD-005123456SD2PD3
234BCD234BCD-006123456SD2PD3
234BCD234BCD-007345678SD4PD3
234BCD234BCD-008345678SD4PD3
234BCD234BCD-009345678SD4PD3
234BCD234BCD-010345678SD4PD3
1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @abrother ,

Create a new calculated column with the following DAX:

Primary Driver = 
VAR CurrentLot = 'Table'[Lot #]
VAR HasSD1 = CALCULATE(
    COUNTROWS('Table'),
    ALLEXCEPT('Table', 'Table'[Lot #]),
    'Table'[Sub-Driver] = "SD1"
)
VAR HasSD3 = CALCULATE(
    COUNTROWS('Table'),
    ALLEXCEPT('Table', 'Table'[Lot #]),
    'Table'[Sub-Driver] = "SD3"
)
RETURN 
SWITCH(
    TRUE(),
    HasSD1 > 0, "PD1",
    HasSD3 > 0, "PD3",
    "Unknown" -- Default value if no rule matches
)

View solution in original post

2 REPLIES 2
Bibiano_Geraldo
Super User
Super User

Hi @abrother ,

Create a new calculated column with the following DAX:

Primary Driver = 
VAR CurrentLot = 'Table'[Lot #]
VAR HasSD1 = CALCULATE(
    COUNTROWS('Table'),
    ALLEXCEPT('Table', 'Table'[Lot #]),
    'Table'[Sub-Driver] = "SD1"
)
VAR HasSD3 = CALCULATE(
    COUNTROWS('Table'),
    ALLEXCEPT('Table', 'Table'[Lot #]),
    'Table'[Sub-Driver] = "SD3"
)
RETURN 
SWITCH(
    TRUE(),
    HasSD1 > 0, "PD1",
    HasSD3 > 0, "PD3",
    "Unknown" -- Default value if no rule matches
)

That worked! Thanks so much!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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