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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
chalapathy
Frequent Visitor

Find row from Table based on value from Measure

I have a measure that calculates remaining units to produce for different items. 

I also have a table that has quantities and unit prices for each item. The table has row number that starts with 1 for each item, quantity and price for that item.

 

Now I want to get the row that has quantity nearest to the value returned by the measure (absolute value) and then get the price value passed to another measure.

 

For example, if the remaining quantity to produce is 2500 tons, and the table has records for 2490 and 2512 tons and corresponding price, I would like to get price from the row corresponding to 2490.

 

Any help appreciated

3 REPLIES 3
Greg_Deckler
Super User
Super User

No sample data so will wing it. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Perhaps:

 

Measure =
  VAR __Table = 
    ADDCOLUMNS(
      ADDCOLUMNS(
          'Table',
          "__Measure",[I have a measure]
      ),
      "__Diff",ABS([Price] - [__Measure])
    )
  VAR __Min = MINX(__Table,[__Diff])
RETURN
  MINX(FILTER(__Table,[__Diff] = __Min),[Price])


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Thanks for the reply. Not able to attached the sample XL file. 

 

Should I copy and paste the table data in the body?

 

 

Result table and requirements (Table PBI_CUM below)

     Reqd:           43,541.33 
DISPLAY IN APP    (Computed measure) 
Measure%usetons_reqdAVPRICEValue   
 (% of Reqd --- user input)reqd*%use

From Table

PBI_CUM

tons_reqd*avprice   
Item115%              6,531.20335.7918572193123.776   
Item21.18%                 513.79326.232921167614.473   
Item3        
Item4        
Item5        
Item6        
Item7        
Item8        
Item9        
Item10        
Item11        
Item12        
Item13        
Total               7,044.99 2360738.249   
        
 AVCOST                 335.09     
Table PBI_CUM have Cum_total and corresponding Value and AVG_PRICE   
        
Objective is to find the row having cum_total that is closest to the measure ofeach item and then return the corresponding AVPrice
Then Calculate AV.Cost based combination of items and their prices.   
        
Item Row No Starts with 1 when the item number chanes and increments by 1 for each record   
There are 13 such items      
        
Additional Help:       
User needs to have the ability to adjust the %use for each item from the app and get the AVCOST.  
   
I am using 13 what-ifs but not able to display the values in tabular form.   

 

Table PBI_CUM

ITEMNMBRItem Row Nocum_totalAVPRICE
Item114887.3839339.48987
Item124887.3839339.48987
Item134906.1428339.42807
Item144906.1428339.42807
Item156351.6116336.1446
Item166424.0669336.24448
Item176444.3884336.17749
Item186464.2634336.11238
Item196480.5848336.00884
Item1106498.4419335.89615
Item1116519.433335.85111
Item1126519.433335.85111
Item1136538.0134335.79186
Item1146558.4866335.74946
Item1156617.5134335.50486
Item1166628.9062335.42018
Item1176628.9062335.42018
Item1186650.683335.47277
Item1197017.0669335.97126
Item1207101.1294336.07838
Item2192.99107316.92118
Item22112.0625317.44518
Item23132.5307.04211
Item24151.29464308.03067
Item25234.10714317.57075
Item26315.98214322.08691
Item27334.15178321.97342
Item28351.94642321.87362
Item29440.60713324.51497
Item210526.94642326.23292
Item211611.76785327.44848
Item212630.33928327.52365
Item213649.75892327.59766

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 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.

Sept NL Carousel

Fabric Community Update - September 2024

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