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
RRaj_293
Helper III
Helper III

Dax Help - Min and Max

Hi , 

 

Scenario- I have a Line Table (A in below pic) which has different orders and their lines for which certain number of days field is calculated. It has negative and positive numbers. The various possibilities are as shown below.

 

A.Line Table  
Order#Line#No of Days
ABC1

-4

 

ABC2-8
ABC3-15
DEF10
XYZ13
XYZ25
XYZ3-10
PQR1-8
PQR2 
PQR317

The above table which is at Line level is aggregated to Order level and another table exists in the Model which has all measures only at the Order level. In this Existing Order table I need to write  a dax to get the below desired result of No of days -

 

Tried this dax - Doesnt seem to work! -

 
NoOfDays_New =
Var nodays = SELECTEDVALUE('Line Table'[NoOfDays])
Return
SWITCH(TRUE(),
                                                            nodays < 0, MAX(-1* MIN('Line Table'[NoOfDays])),
                                                            nodays > 0, MAX('Line Table'[NoOfDays]),
                                                            nodays = 0 , "On Time" )
B.Expected results( At Order level) 
Order#No of Days 
ABC-15 
DEF0 
XYZ-10 
PQR  
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@RRaj_293 try this measure: but you have to turn on show items with no data because when you are returning BLANK () where the

No of Days Measure = 
VAR __MaxDays = MAXX ( Orders, [No of Days] )
VAR __MinDays = MINX ( Orders, [No of Days] )
VAR __CountBlank = COUNTROWS ( FILTER ( Orders, ISBLANK ( [No of Days] ) ) )
RETURN
IF ( __CountBlank >= 1, BLANK (), IF ( __MinDays < 0, __MinDays, __MaxDays ) ) 

 

Tweak the above measure as you see fit, as I didn't understand the full logic.

 

parry2k_0-1694393028550.png

 

order has a blank number of days by default any visual will suppress that rows:

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
RRaj_293
Helper III
Helper III

Thank you all for responding. I was able to resolve it using below dax-

IF ( (COUNTBLANK( 'Line'[NoOfDays] )>=1 ),BLANK(),IF((SELECTEDVALUE('Line'[NoOfDays]))<=0, MIN('Line',' Line'[NoOfDays]), MAX('Line','Line'[NoOfDays]))),
parry2k
Super User
Super User

@RRaj_293 Cannot tell, I tested on the sample you provided and it worked. You cannot compare with 0 because blank is deemed as zero and that's why I had that special logic in place to count the blank rows.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@RRaj_293 try this measure: but you have to turn on show items with no data because when you are returning BLANK () where the

No of Days Measure = 
VAR __MaxDays = MAXX ( Orders, [No of Days] )
VAR __MinDays = MINX ( Orders, [No of Days] )
VAR __CountBlank = COUNTROWS ( FILTER ( Orders, ISBLANK ( [No of Days] ) ) )
RETURN
IF ( __CountBlank >= 1, BLANK (), IF ( __MinDays < 0, __MinDays, __MaxDays ) ) 

 

Tweak the above measure as you see fit, as I didn't understand the full logic.

 

parry2k_0-1694393028550.png

 

order has a blank number of days by default any visual will suppress that rows:

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks @parry2k  . I tried this and logically looks right to me as well but not sure why the records are all blank. I have enabled 'show items with No data'.  If I remove the blank count and just do Min , Max it works except for blank scenarios.

 

if((SELECTEDVALUE('Line'[NoOfDays]))<=0, Min('Line'[NoOfDays]), MAX('Line'[NoOfDays])),

RRaj_293_0-1694396838133.png

 

RRaj_293
Helper III
Helper III

Hi @lbendlin  , Thanks for responding. Yes I got the same using If condition , but the challenge is with the blanks. I have modified the data in the table and the expected reuslts. If there is a combination of +ve , -ve and blank within an order then I need blank displayed at the order level as we are reporting the worst case scanerios . A blank indicates the order is not yet despatched likein order example PQR. If the order has only +ve and -ve's then display the min(farthest) negative number as that indiactes the most number of days taken(worst case scenario) like in example order XYZ.

 

Note - Table data edited for these scenarios in my original post.

lbendlin
Super User
Super User

lbendlin_0-1694291125392.png

Slightly refactored:

 

Order level = 
var mxx = maxx('Table',[No of Days])
return if (mxx<0,minx('Table',[No of Days]),mxx)

 

 

 

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.