ALLEXCEPT Highest revenue and Category of the day per Customer

propi_

New Member
Joined
Jun 11, 2014
Messages
19
Dear Dax Pro's

i have a Case my DAX Knowledge exceeds. I have a Dataset, and i want to use the ALLEXCEPT in a more complex way.

IDCustomer_idOrder_of_n_dayOrderDayRevenueDateOrder noCategoryMaxCategory
Revenue_of_max_category
1100
112729.07.2015 00:00885689VP49,19
21002122,3629.07.2015 00:00885690FP49,19
31003149,19
29.07.2015 00:00885691
PP49,19
41004118,0229.07.2015 00:00885692FP49,19
510012108,401.09.2015 00:00885693SS108,4
6100132707.11.2016 00:00885694VV127
71002360,1707.11.2016 00:00885695PV127
81003310007.11.2016 00:00885696VV127
9200
112729.08.2015 00:00885697VP50
102002122,3629.08.2015 00:00885698FP50
11200315029.08.2015 00:00885699PP50
122004118,0229.08.2015 00:00885700FP50
132001220001.10.2015 00:00885701SS200
14200132717.11.2016 00:00885702VV227
152002360,1717.11.2016 00:00885703PV227
162003320017.11.2016 00:00885704VV227

<tbody>
</tbody>

All is given except
MaxCategory
Revenue_of_max_category

<tbody>
</tbody>


-My Problem is, I want to find for each Customer the Category with the highest Revenue on the Order Day, flag all other with that Category and also want to know that Revenue.
-The other Problem is, if there has been 2 Orders of the same category on that day, it should be summarized first in the calculation (Highest revenue of that Category of the day per Customer).

Is this even possible in DAX in a performant way? ALLEXCEPT and EARLIER worked pretty fast for me so far. Maybe it's more a "SQL Rank over Partition by" thing :)

Thank you guys in advance! You are the best!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi propi_,

First off, you should probably create measures rather than calculated columns for this sort of thing.
Calculated Columns vs Measures in DAX - Excelerator BI

In any case, here's how you could create the calculated columns. Measures would be similar but different since there would be no row context and you would have to decide how to handle multiple date/customer selection.

Revenue_of_max_category (calculated column)
Code:
=
    CALCULATE (
        MAXX (
            VALUES ( YourTable[Category] ),
            CALCULATE ( SUM ( YourTable[Revenue] ) )
        ),
        ALLEXCEPT ( YourTable, YourTable[Customer_id], YourTable[Date] )
    )

MaxCategory (calculated column)
Code:
=
    CALCULATE (
        FIRSTNONBLANK (
            TOPN (
                1,
                VALUES ( YourTable[Category] ),
                CALCULATE ( SUM ( YourTable[Revenue] ) )
            ),
            1
        ),
        ALLEXCEPT ( YourTable, YourTable[Customer_id], YourTable[Date] )
    )
 
Upvote 0
Dear Owen,

code works flawless and superfast! Big thank you for that! DAX is the way to go :cool:
You're right. Measures would be better (at least for the Max Revenue). Dimensions as the category are more "dynamic" when put to the measurelines in my opinion.

How do i read the first code?: Calculate the max value (revenue) for the categories over customer and date?


I have also calculated the daily revenue as follows:

Code:
    =[COLOR=#0000ff]CALCULATE[/COLOR](
                [COLOR=#0000ff]SUM[/COLOR]([COLOR=#000000]yourTable[Revenue][/COLOR]);
                [COLOR=#0000ff]ALLEXCEPT[/COLOR](yourTable;[COLOR=#000000]yourTable[Customer_id][/COLOR];[COLOR=#000000]yourTable[Date][/COLOR])
             )

When put as an measure it works. I know, I shouldn't, but for Evaluation i'd also like to write the daily Revenue only to the first Order of the day like:

IDCustomer_idOrder_of_n_dayOrderDayRevenueDateOrder noCategoryMaxCategoryRevenue_of_max_categoryEval_dayRevenue
1100112729.07.2015 00:00885689VP49,19116,57
21002122,3629.07.2015 00:00885690FP49,190
31003149,1929.07.2015 00:00885691PP49,190
41004118,0229.07.2015 00:00885692FP49,190
510012108,401.09.2015 00:00885693SS108,4108,4
6100132707.11.2016 00:00885694VV127187,17
71002360,1707.11.2016 00:00885695PV1270
81003310007.11.2016 00:00885696VV1270
9200112729.08.2015 00:00885697VP50117,38
102002122,3629.08.2015 00:00885698FP500
11200315029.08.2015 00:00885699PP500
122004118,0229.08.2015 00:00885700FP500
132001220001.10.2015 00:00885701SS200200
14200132717.11.2016 00:00885702VV227287,17
152002360,1717.11.2016 00:00885703PV2270
162003320017.11.2016 00:00885704VV2270

<tbody>
</tbody>


I know that EARLIER() in an IF() clause is the way to go, but now things are getting too complex for me :)

Here's my other EARLIER Code i used:

Code:
=[COLOR=#0000ff]IF[/COLOR]([COLOR=#000000][id][/COLOR]
      =[COLOR=#0000ff]CALCULATE[/COLOR]([COLOR=#0000ff]Min[/COLOR]([COLOR=#000000][id][/COLOR]);[COLOR=#0000ff]ALL[/COLOR](yourTable);[COLOR=#000000]yourTable[Customer_id][/COLOR] =[COLOR=#0000ff]EARLIER[/COLOR]([COLOR=#000000][Customer_id][/COLOR]));[COLOR=#000000][Revenue][/COLOR];[COLOR=#00008b]0[/COLOR])

But this only works over [id] for all Days, but I want to calculate within days :)

Thanks in advance and have a great day!
-Andy
 
Upvote 0

Forum statistics

Threads
1,214,847
Messages
6,121,911
Members
449,054
Latest member
luca142

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top