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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.

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

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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