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
ssr80
Frequent Visitor

How to select a Max Value in a given month for each customer?

Hi Everyone,

Can someone help me with the following scenario.

 

I have one table for orders and one table with customer details

 

Orders.JPG

 

 

 

 

 

 

 

  

 

 

 

i need to create a table with CustomerID, Month and Highest order value in that paticular month.

Result should look like below:

result.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Any help would be appreciated. 

 

regards

SS

2 ACCEPTED SOLUTIONS

Hi Phil,

Great job, That's awesome.

it works as per my requirement.

 

Thanks for all your efforts.

 

Regards

SS

 

View solution in original post

@ssr80,

 

By the way, you may help accept solution. Your contribution is highly appreciated.

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

View solution in original post

8 REPLIES 8
Phil_Seamark
Employee
Employee

Hi @ssr80

 

This Calculated Table looks close.  Just replace where I have Table2 with the name of your table.

 

 

Table = 
VAR tblMonths = 
    SUMMARIZE(
        ADDCOLUMNS(
            CALENDAR("2017-11-01","2018-01-01"),
            "Month",DATE(YEAR([Date]),MONTH([Date]),1)
            ),[Month])
            
RETURN    
    ADDCOLUMNS(
        GENERATE(
            VALUES('Table2'[Customer]),
            tblMonths
            )
            ,"Order Value" , 
                CALCULATE(
                    MAX('Table2'[Order Value]),
                    FILTER('Table2',
                    'Table2'[Customer] = EARLIER('Table2'[Customer]) && 'Table2'[Date] = EARLIER([Month])
                    )
                    ))

 

 

gen.png

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil,

Thanks for the reply. that was great, appreciate your effort.

 

there is a small error in the results.

it's giving me the right value only when the order is placed on 01st of the month.

But, if the order is placed on other days of the month. it's returning null.

 

sorry, may be my question wasn't clear.

the order date is actually in the format of date and time.

 

Regards

SS

 

HI @ssr80

 

Please try this slight modification.  I have marked in bold (red) the change.

 

Table = 
VAR tblMonths = 
    SUMMARIZE(
        ADDCOLUMNS(
            CALENDAR("2017-11-01","2018-01-01"),
            "Month",DATE(YEAR([Date]),MONTH([Date]),1)
            ),[Month])
            
RETURN    
    ADDCOLUMNS(
        GENERATE(
            VALUES('Table2'[Customer]),
            tblMonths
            )
            ,"Order Value" , 
                CALCULATE(
                    MAX('Table2'[Order Value]),
                    FILTER('Table2',
                    'Table2'[Customer] = EARLIER('Table2'[Customer]) && DATE(YEAR('Table2'[Date]),MONTH('Table2'[Date]),1) = EARLIER([Month])
                    )
                    ))

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil,

Great job, That's awesome.

it works as per my requirement.

 

Thanks for all your efforts.

 

Regards

SS

 

@ssr80,

 

By the way, you may help accept solution. Your contribution is highly appreciated.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ssr80
Frequent Visitor

Hi Phil,

further to this topic.

 

orders are recorded in dd/mm/yyyy tt:hh:ss format.

But, i need to report monthwise highest order value for each customer.

 

Thank you.

 

Regards

SS

 

Hi @ssr80,

 

Share your two datasets (that can then be pasted in MS Excel)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

Here is the two datasets i have.

 

1 table with the list of orders

Ord   CustomerID    Date                        OrderType

1        10530           7/02/2018 14:17      -1
2        10520           5/02/2018 15:58        3
3        10520           5/02/2018 14:07       -1
4         10520          5/02/2018 13:37       -1
5        10520          5/02/2018 13:29       -1
6        10517          5/02/2018 15:24       -1
7        10517          6/02/2018 3:00           3
8        10512         1/02/2018 2:09           3
9        10496         1/02/2018 11:31         3
10      10496         1/02/2018 11:27        -1

2nd table 

 CustomerID     MonthYear       
10532               Feb-18 
10531               Feb-18 
10530               Feb-18 
10528               Feb-18 
10527               Feb-18 
10526               Feb-18 
10520               Feb-18 
10517               Feb-18 
10514                Feb-18 
10512               Feb-18            
10499               Feb-18 
10496               Feb-18     

 

the result should have customerID, MonthYear, MaxOrderType for the month

i am getting the following result when i try the solution from Phil.

as you can see from the orders table

customerID 10520 should have value 3

customerID 10517 should have value 3

and so on.

 CustomerID     MonthYear       MaxOrdertype
10532               Feb-18
10531               Feb-18
10530               Feb-18
10528               Feb-18
10527               Feb-18
10526               Feb-18
10520               Feb-18
10517               Feb-18
10514                Feb-18
10512               Feb-18             3
10499               Feb-18
10496               Feb-18             3


Any help would be appreciated. 

Thanks.

 

Regards

SS

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.