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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pstanek
Post Patron
Post Patron

MAX MIN

I have table with columns

 

Office -Product-  Stock Value.

I need to create  Product - MIN Stock - Office with min stock - Max stock - Office with max stock

 

I try to avoid to order new products for one office, when another has too many products.

 

For example product_i was sold out by one office, another could sell only few product.

 

Do you have any idea?

 

Another step should be identifying products with largest Max stock - Min Stock.

12 REPLIES 12
KHorseman
Community Champion
Community Champion

Min Stock = MIN(StockTable[Stock])

 

Office with Min Stock = CALCULATE( LASTNONBLANK(StockTable[Office], 1),

FILTER( StockTable, StockTable[Stock] = MIN(StockTable[Stock]))

 

Max Stock = MAX(StockTable[Stock])

 

Office with Max Stock = CALCULATE( LASTNONBLANK(StockTable[Office], 1),

FILTER( StockTable, StockTable[Stock] = MAX(StockTable[Stock]))





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

Proud to be a Super User!




Is LASTNONBLANK supported in direct query?

@pstanek I don't think so. If your offices are numbered you could use MAX(StockTable[Office]) instead of LASTNONBLANK. If Office is a text field maybe something like CONCATENATE(StockTable[Office], "") I am not sure what to do about that. You need some way to get a single row value and LASTNONBLANK/FIRSTNONBLANK is the only way I know of for that.





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

Proud to be a Super User!




Figured it out. I was close with CONCATENATE but not quite right.

 

Office with Min Stock = CALCULATE( CONCATENATEX(VALUES(StockTable[Office]), StockTable[Office],

FILTER( StockTable, StockTable[Stock] = MIN(StockTable[Stock])

 





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

Proud to be a Super User!




Thanks, It works for some examples. 

 

  I have another idea, but I dont know , if it is possible.

 Can I sort table by levels? I have table within report. I would like to sort it by product, and second level by office. Is it possible?

 

I need to find solution, when stock table exists only within report, but it is not in query. I mean it has been created  through relations.

Anonymous
Not applicable

Hi @pstanek,

Do you want to sort the table in Report view or Data view of Power BI Desktop? Could you please show sample data of your table and post the expected result?


Thanks,
Lydia Zhang

It is similar to this , so I tried to use its solution. Using Matrix

 

https://community.powerbi.com/t5/Desktop/Sort-a-table-by-the-results-of-two-columns/m-p/16299#M4485

 

 

I am not really sure what the difference is . I mean difference between table in Report view or Data view of Power BI Desktop.

 

Result of using matrix is sufficient for now.

The data view is just the raw tables in your data model. The report view is for building the visuals that the end users will see and interact with. A matrix is one of those visuals, just as a bar chart is.





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

Proud to be a Super User!




So that is why export data will export raw tables , not report view.

Every visual is sort of just a calculated table generated by measures and filter contexts, with a coat of paint on top. Export gives you that calculated table, minus the pretty picture the visual painted with it.





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

Proud to be a Super User!




Sean
Community Champion
Community Champion

Wow @KHorseman that's perfectly worded!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.