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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Thomas_MedOne
Helper II
Helper II

Return value from row/column based on another row/column

I haven't seen this exact scenario or even something close to it so I'm hoping someone here can help.  I have a table with several columns, these are the relevant ones below.  

 

A person works a shift and he gets paid productivity for the sales in that shift. But they may actually work an "Add on" Shift which carries additional responsibilities. But productivity is assigned to the original shift he is in so productivity in the add-on shift is blank.

 

What I would like to figure out is can I copy the productvity of the other shift IF he has worked it on the same day. So the data looks like this: (Notice there can be two different types of shifts that day.

 

PersonShift DateShift NameLocationProductivity
Dave Jones3/1/2024AMC ShiftMH0
Dave Jones3/1/20247-4 ShiftMH445
Mark Castle3/2/2024AMC ShiftMH0
Mark Castle3/2/20247-4 Shift 2MH451
Dave Jones3/2/20247-4 ShiftMH422

 

Location probably shouldn't factor in. They can work at different locations but it is not likely they will be in the AMC shift at one location and another at the same time. that doesn't happen.

 

I would like to copy the productivity from the 7-4 shift to the AMC shift when they work the same day. Of course, Dave Jones 3/2 would not copy anywhere because he didn't also work the AMC shift.

1 ACCEPTED SOLUTION
Thomas_MedOne
Helper II
Helper II

I cleaned it up a bit to look like this:

 

FinalProd =
VAR Shift1 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift")
VAR Shift2 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 2")
VAR Shift3 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 3")

RETURN If ('Schedule'[Shift Name] = "AMC Shift",
If (Shift1,Shift1,
If(Shift2,Shift2, Shift3)),
'Schedule'[Productivity])

View solution in original post

4 REPLIES 4
v-yohua-msft
Community Support
Community Support

Hi, @Thomas_MedOne 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

Best Regards

Yongkang Hua

Thomas_MedOne
Helper II
Helper II

I cleaned it up a bit to look like this:

 

FinalProd =
VAR Shift1 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift")
VAR Shift2 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 2")
VAR Shift3 = LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 3")

RETURN If ('Schedule'[Shift Name] = "AMC Shift",
If (Shift1,Shift1,
If(Shift2,Shift2, Shift3)),
'Schedule'[Productivity])

ValtteriN
Super User
Super User

Hi,

If you want to do this in dax something like this should do:

Measure 28 = CALCULATE(MAX('Table (39)'[Productivity]),ALL('Table (39)'[Shift Name]))

Here we are not "copying" the value, but instead removing the shift from consideration with ALL. This way we take the maximum productivity and apply that to all the values.


End result:
ValtteriN_0-1715355751236.png

 

Here Dave Jones 3/2/2024 keeps the value 422 as expected.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




that doesn't seem to be working for me. It's outputting zero.

 

This is not as elegant at all but I did find a way to do it by creating a new column. It looks like this:  there are three potential shifts to match with the name and the date. So, I first see if it's the AMC shift, then I search for the other shifts that could have the same prod. If they contain data, then return it, if not, for all three, just copy the prod from the prod field.  that is working for me.

 

FinalProd = If ('Schedule'[Shift Name] = "AMC Shift",
If (LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift"),
LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift"),
If(LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 2"),
LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 2"),
LOOKUPVALUE('Schedule'[Productivity],'Schedule'[Shift Date],'Schedule'[Shift Date],'Schedule'[POSITION NAME],'Schedule'[POSITION NAME],'Schedule'[Shift Name],"7-4 Shift 3"))),
'Schedule'[Productivity])

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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