Forum Discussion

Lygral63's avatar
Lygral63
Icon for Helper I rankHelper I
2 years ago
Solved

DAX measure (Max/Min)

DAX measures for Max and Min

 

I am looking for the best way to calculate a measure that will compare sales from multiple year in a given Calendar Week and returning the max value. The measure should return the max by Calendar Week based on total sales (eg. sum of countries). I would need the same kind of measure for Min. Any suggestions?

 

Table: Data     
      
CountryProductYearCalendar Week Sales 
AC20151100 
AC20152200 
AC20161150 
AC20162125 
BC20151200 
BC20152250 
BC20161100 
BC20162150 
      
      
Calendar WeekYearTotal Sales   
12015300   
12016250   
22015450   
22016275   
      
Output     
      
Measure should return:    
      
Calendar Week     
1300    
2450    
      

 

  • Yes, it's works. Thanks a lot. Much more simple than I expected. Thanks.

8 Replies

  • Dangar332's avatar
    Dangar332
    Icon for Resident Rockstar rankResident Rockstar

    Hi, Lygral63 

     

    try below code 

     

    min sales by week = MIN('calender week'[Total Sales])

     

    max sales by week = max('calender week'[Total Sales])

     

     

    • Lygral63's avatar
      Lygral63
      Icon for Helper I rankHelper I

      Thanks, but I don't think that works. I need a measure that looks at total sales by Year and by Calendar Week and then returns the max or min value. It could be that in Calendar Week 1 has the max value based on sales in 2016, but Calendar 2 has the max value based on sales in 2015. Hope it makes sense.

    • Lygral63's avatar
      Lygral63
      Icon for Helper I rankHelper I

      I appreciate the effort, but I can't the the result I am expecting. The problem is that I have multiple years and need to max value from Calendar Week 1 (across all years), then the max from Calendar Week 2 (across all years) etc. So in total the measure should return the max value for every Calendar Week comparing data from all years.  I hope that makes it a bit more clear.

       

      • Dangar332's avatar
        Dangar332
        Icon for Resident Rockstar rankResident Rockstar

        Hi, Lygral63 

         

        try below 

        result =
        calculate(max('table (2)'[total sales]),removefilters(''table (2)'[year]))

         

         

        if not work then provide week1 and week 2 data