Forum Discussion

TimK's avatar
TimK
Icon for Helper III rankHelper III
4 years ago
Solved

Extracting Corresponding Date from Totals

Welcome some help with this please!

 

I am having great problems!

 

I have some sample data:

 

Product01/01/202301/02/202301/03/202301/04/202301/05/202301/06/202301/07/202301/08/202301/09/202301/10/202301/11/202301/12/202301/01/202401/02/2024
A1255223322 33  22    
B1159 333321222      
A 222335 2113      
A      22 2489211  
A 2236 92233 3333
B 5822885       

 

Basically I am after a table that will then give me for each Product, the totals per month such as this:

 

Product01/01/202301/02/202301/03/202301/04/202301/05/202301/06/202301/07/202301/08/202301/09/202301/10/202301/11/202301/12/202301/01/202401/02/2024
A129981683146862711124433
B111172354129722000000

 

And then finally, a table that gives me the maximum value, and the corresponding date:

ProductMax ValueDate
A11101/10/2023
B11701/02/2023

 

Grateful for any help

  • So, first you need the TOTAL for each Product and Month, right? With that, you can select the Month with the highest sales?

     

    MaxValue Per Product = MAXX(SUMMARIZE('Table','Table'[Date].[Year],'Table'[Date].[Month],'Table'[Product]),
                           CALCULATE(SUM('Table'[Value])))

     

    Max Value Date = 
    
    VAR MaxValue =
    MAXX(SUMMARIZE('Table','Table'[Date].[Year],'Table'[Date].[Month],'Table'[Product]), CALCULATE(SUM('Table'[Value])))
    
    RETURN
    CALCULATE(VALUES('Table'[Date]),
    FILTER(ALL('Table'[Date]), [MaxValue Per Product] = MaxValue))

     

    With my dummy file I got the result as expected I think.

     

    Data (not that in February Product A sums up 14, which is the higher value for Product A, while Product B sums up 16 in April):

    Outcome:

     

    If that's not what you want, then please could you share your .Pbix?

7 Replies

  • Ale's avatar
    Ale
    Icon for Resolver II rankResolver II

    As the colleague danextian mentioned, ideally you should unpivot your data in order to have 1 column with all the dates.

     

    Once this is done, you can achieve what you want by doing the following:

     

    1 Measure for Max Value:

    MaxValue Per Product = MAX('Table'[Value])

     

    1 Measure to get Date for that Max Value:

    Max Value Date = 
    
    VAR MaxValue =
    CALCULATE(MAX('Table'[Value]),
    ALLSELECTED('Table'[Date]))
    
    RETURN 
    CALCULATE(VALUES('Table'[Date]),
    FILTER(ALL('Table'[Date]), [MaxValue Per Product] = MaxValue))

     

    In your table visual, just add the Product to the Rows and these 2 Measures to the Values.

    • TimK's avatar
      TimK
      Icon for Helper III rankHelper III

      hi Ale

       

      Thanks for that......

       

      So i probably was not clear - sorry......

       

      First we need to create data as per the second table - so each product listed once, with the TOTALS for each product....

       

      Then the challenge is to find the month with the highest TOTAL, not initial figure.....

      Does that make sense?  Sorry. 🙂

      • Ale's avatar
        Ale
        Icon for Resolver II rankResolver II

        So, first you need the TOTAL for each Product and Month, right? With that, you can select the Month with the highest sales?

         

        MaxValue Per Product = MAXX(SUMMARIZE('Table','Table'[Date].[Year],'Table'[Date].[Month],'Table'[Product]),
                               CALCULATE(SUM('Table'[Value])))

         

        Max Value Date = 
        
        VAR MaxValue =
        MAXX(SUMMARIZE('Table','Table'[Date].[Year],'Table'[Date].[Month],'Table'[Product]), CALCULATE(SUM('Table'[Value])))
        
        RETURN
        CALCULATE(VALUES('Table'[Date]),
        FILTER(ALL('Table'[Date]), [MaxValue Per Product] = MaxValue))

         

        With my dummy file I got the result as expected I think.

         

        Data (not that in February Product A sums up 14, which is the higher value for Product A, while Product B sums up 16 in April):

        Outcome:

         

        If that's not what you want, then please could you share your .Pbix?

    • TimK's avatar
      TimK
      Icon for Helper III rankHelper III

      hi Ale

       

      BINGO - you have done it - thank you very much......

       

      I may have supplementary questions in a few days!!

      Thank you for your help with this