cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Shelley
Continued Contributor
Continued Contributor

How to Look at one row in a set and select other rows from which to extract fields for calculations

Hi All,

I'm looking for some help in selecting data from one row, using it to select data in another row, and then performing a calculation. We have contract data. Each contract can have multiple Main lines and then each Main line has corresponding Sublines. I need to take data from a specific Main line and find the first corresponding subline, and use data from it to perform a calculation.

 

Contract NumberLine Item NumberMaterial IDMaterialMain/Sub IndicatorLine Item Target QuantityLine Item Target Quantity UOMLine Item Target Value
41596100PN-C01522Maintenance Contract ServiceM1EA54815
41596110PN-C20155Contract 1.0 LaborS330.11STD54815.12
41596120PN-C20155Contract 1.0 LaborS1STD166.05
41596130PN-C20161Contract 1.5A OT LaborS1STD249.08
41596140PN-C20161Contract 1.5A OT LaborS1STD249.08
41596150PN-C20163Contract 2.0A OT LaborS1STD332.1
41596160PN-C20163Contract 2.0A OT LaborS1STD332.1

 

1. First I need to find Main/Sub Indicator = M that also has PN-C01522 and use the Line Item Target Value

2. Then, given the Main line that matches this criteria is line item number 100, find the next in sequence Sub-Line Item Number (in this case, 110), so Main/Sub Indicator = S and ensure the material ID is PN-C20155 and grab the Line Item Target Quantity of 330.11.

3. Then I want to divide the Line Item Target Value by the Line Item Target Quantity.

 

The results would look like this (1st row, based on the above):

Contract NumberLine Item Target ValueEntitlement QtyPer Unit
4159654815330.11166.05
99999250025100.00
88888600058103.45

 

Anyone know some easy way to do this?

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi @Shelley 

Please try to create two measure as below:

Entitlement Qty = 
VAR _nextlinenumber=CALCULATE(MIN('Table'[Line Item Number]),FILTER(ALLEXCEPT('Table','Table'[Contract Number]),'Table'[Line Item Number]>MAX('Table'[Line Item Number]))) 
return
CALCULATE(SUM('Table'[Line Item Target Quantity]),FILTER(ALLEXCEPT('Table','Table'[Contract Number]),'Table'[Line Item Number]=_nextlinenumber))
Per Unit = DIVIDE(CALCULATE(SUM('Table'[Line Item Target Value])) ,[Entitlement Qty],0)

Result:

9.JPG

and here is sample pbix file, please try it.

 

Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Shelley
Continued Contributor
Continued Contributor

@Greg_Deckler Thank you! This appears to work, but our data is sketchy and so I need to make sure this is robust. Is there any chance, you could please explain what each expression is doing? I try to use the Microsoft reference docs, but they are usually impossible to understand in regards to application.

Shelley
Continued Contributor
Continued Contributor

@Greg_Deckler Thank you! Your suggestion seems to work for Item #1, but how do I do Item # 2? That is, how do I select the next Line Item Number in sequence (110) and then grab the Line Item Quantity from that row and only that row?

Greg_Deckler
Super User
Super User

@Shelley - Seems like a measure with some straight-up FILTERs, like:

 

Measure = 
  VAR __Contract = MAX('Table'[Contract Number])
RETURN
  MAXX(FILTER('Table',[Contract Number] = __Contract && [Main/Sub Indicator] = "M" && [Material ID] = "PN-C01522"),[Line Item Target Value])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors