Weird Sum DAX help...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi Team,

Looking for some DAX to achieve the following...

Data as follows:
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
[TABLE="class: tableizer-table"]
<tbody>[TR="class: tableizer-firstrow"]
[TH]Shop
[/TH]
[TH]Type
[/TH]
[TH]Week
[/TH]
[TH]Amount
[/TH]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Bag
[/TD]
[TD]1
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Bag
[/TD]
[TD]2
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Bag
[/TD]
[TD]3
[/TD]
[TD]12
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Box
[/TD]
[TD]1
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Box
[/TD]
[TD]2
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]Box
[/TD]
[TD]3
[/TD]
[TD]12
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]Bag
[/TD]
[TD]1
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]Bag
[/TD]
[TD]2
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]Bag
[/TD]
[TD]3
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]Bag
[/TD]
[TD]1
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]Bag
[/TD]
[TD]2
[/TD]
[TD]20
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]Bag
[/TD]
[TD]3
[/TD]
[TD]20
[/TD]
[/TR]
</tbody>[/TABLE]

Result as follows:
<style type="text/css">
table.tableizer-table {
font-size: 12px;
border: 1px solid #CCC ;
font-family: Arial, Helvetica, sans-serif;
}
.tableizer-table td {
padding: 4px;
margin: 3px;
border: 1px solid #CCC ;
}
.tableizer-table th {
background-color: #104E8B ;
color: #FFF ;
font-weight: bold;
}
</style>
[TABLE="class: tableizer-table"]
<tbody>[TR="class: tableizer-firstrow"]
[TH]Week
[/TH]
[TH]Amount
[/TH]
[/TR]
[TR]
[TD]1
[/TD]
[TD]35
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]45
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]42
[/TD]
[/TR]
</tbody>[/TABLE]

The result was achieved as follows:

Where more than one Type exists for a given Shop / Week combination, take the MAX Amount for that Shop / Week across ALL Types, otherwise just take the Amount. Finally, Sum the resulting values up for each Week.

I've had a play myself but can't quite get it, hence the ask.

Cheers,

Matty
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi there Matty,

I would do something like this:

Code:
Weird Sum =
SUMX (
    SUMMARIZE ( Sales, Sales[Week], Sales[Shop] ),
[COLOR=#ff0000][B]    CALCULATE ([/B][/COLOR]
        MAXX ( VALUES ( Sales[Type] ), CALCULATE ( SUM ( Sales[Amount] ) ) )
[COLOR=#ff0000][B]    )[/B][/COLOR]
)

It basically says, for each Week/Shop combination, take the maximum Amount (sum) across Types.
If there is only one Type, then it is the maximum by default.

The red CALCULATE can be omitted and you still get the same result, but it may improve performance, as it ensures the MAXX iterates only over Types that exist for each Week/Shop combination.

Does this work for you?

Cheers,
Owen
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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