Calculated table using DAX...

Matty

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

I'm looking for some help creating a calculated table using DAX to work out what Products make up the top N % of my portfolio based on Sales.

My raw data table is as follows:

ProductSales
A10
B15
D25
E15
F5
E10
D30
C25
A40
B5

<tbody>
</tbody>

Running through the logical steps in my head, the next task would be to summarise Sales by Product:

ProductSales
A50
B20
C25
D55
E25
F5

<tbody>
</tbody>

This table would then need to be sorted by Sales:

ProductSales
D55
A50
C25
E25
B20
F5

<tbody>
</tbody>

Next would be to work out the % of Total each Product represents:

ProductSales% of Total
D5531%
A5028%
C2514%
E2514%
B2011%
F53%

<tbody>
</tbody>

Finally, we would calculate the % of Running Total:

ProductSales% of Total% of Total Running
D5531%31%
A5028%58%
C2514%72%
E2514%86%
B2011%97%
F53%100%

<tbody>
</tbody>

Ultimately, all I am after in terms of my DAX table is the following:

ProductSales
D31%
A58%
C72%
E86%
B97%
F100%

<tbody>
</tbody>

Hope the above makes sense and someone can set me on my way.

Thanks,

Matty
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Interesting!

RANKX() give you the rank of a particular item by category, so:

Code:
Total Sales:=
SUM(Sales)

Product Rank:=
RANKX(
    ALL(Table[Product]),
    [Total Sales]
)

Running Total:=
CALCULATE(
    [Total Sales],
    FILTER(
        ALL(Table[Product]),
        [Product Rank]<=VALUES([Product Rank])
    )
)

Running Percent:=
DIVIDE(
    [Running Total],
    CALCULATE(
        [Total Sales],
        ALL(Table)
    )
)
 
Last edited:
Upvote 0
Code:
Cumulative Sales = 
CALCULATE(
 [Total Sales],
 topn(
  [Product Rank],
  ALL(Table1[Product]),
  [Total Sales]
 )
)
 
Upvote 0
That's great, gazpage! Many thanks for showing me the way. I am slowly getting my head around DAX... I think!

Cheers,

Matty
 
Upvote 0
Hi,

All works well, but my real data actually has a hierarchy associated with it, which I want to be able to slice on and then see the appropriate data.

Below is an example of the data layout:

ShopProductSales
1A10
2B15
1D25
1E15
2F5
1E10
1D30
1C25
2A40
2B5

<tbody>
</tbody>

So, the solution provided works well, but if I slice on Shop, the Running Percent doesn't account for the fact I'm looking at a subset of the data (Shop 2).

I've had a play around with FILTER, but I can't get things to work unless I hard code the Shop number into the DAX formula.

Any ideas?

Cheers,

Matty
 
Upvote 0
Likely just overzealous use of ALL() in my code. Anywhere you are using ALL() make sure it includes the column name i.e. ALL(Table[Product]).

If that doesn't fix it could you please drop the four measures into a table and let us know at which step it goes wrong?
 
Upvote 0
Seems my internet is down, but if changing the column reference doesn't work then also try replacing ALL() with ALLSELECTED() (only at the step it goes wrong).
 
Upvote 0
Likely just overzealous use of ALL() in my code. Anywhere you are using ALL() make sure it includes the column name i.e. ALL(Table[Product]).

If that doesn't fix it could you please drop the four measures into a table and let us know at which step it goes wrong?

The overzealousness was to blame! Thanks!

Matty
 
Upvote 0
Yeah, my bad. If you end up filtering any of you products out it will go wrong again. In that case you'd need ALLSELECTED.
 
Upvote 0

Forum statistics

Threads
1,216,210
Messages
6,129,525
Members
449,515
Latest member
lukaderanged

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