DAX Measures

wesley.yau

New Member
Joined
Nov 19, 2012
Messages
3
I have two sets of data set up as shown below.

Records of items sold - keeps track of the number of coloured shapes sold.
Shape
Colour
Volumn
Sphere
Red
20
Sphere
Blue
10
Sphere
White
5
Sphere
Red
30
Rectangle
Blue
40
Rectangle
White
25
Rectangle
Red
35
Rectangle
Blue
30
Rectangle
White
20

<TBODY>
</TBODY>


Total number of items in stock
Shape
Colour
Stock
Sphere
Red
100
Sphere
Blue
130
Sphere
White
120
Rectangle
Red
130
Rectangle
Blue
140
Rectangle
White
150

<TBODY>
</TBODY>
But total sphere cannot be sold more than 300 and total rectangle cannot be sold more than 350

How do I go about setting up a custom "Percentage Sold" measure like the following?

[Shape] [Colour] [Percentage Sold]
Sphere Red 50% (50 / 100)
Sphere Blue 7.69% (10 / 130)
Sphere White 4.17% (5 / 120)
Total Sphere 21.67% (Instead of 65 / 350, I need 65 / 300)

Same goes for rectangle.

Any help would be appreciated, thanks!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I've just realised this was in "PowrPivot", but the code may be of some Help !!!
With you Stock items in Columns "A,B & C" and you Sold Items in Columns "F,G & H", Starting row1 with the headers.
This code will provide results in column "D" starting "D2".
Code:
[COLOR=navy]Sub[/COLOR] MG19Nov33
[COLOR=navy]Dim[/COLOR] Rng         [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Dn          [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] shp         [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("F2"), Range("F" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    shp = Dn & Dn.Offset(, 1)
    [COLOR=navy]If[/COLOR] Not .exists(shp) [COLOR=navy]Then[/COLOR]
        .Add shp, Dn.Offset(, 2)
    [COLOR=navy]Else[/COLOR]
         .Item(shp) = .Item(shp) + Dn.Offset(, 2)
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    shp = Dn & Dn.Offset(, 1)
        [COLOR=navy]If[/COLOR] .exists(shp) [COLOR=navy]Then[/COLOR]
            Dn.Offset(, 3) = Format(.Item(shp) / Dn.Offset(, 2), "0.00%") & " (" & .Item(shp) & "/" & Dn.Offset(, 2) & ")"
        [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] Dn
[COLOR=navy]End[/COLOR] [COLOR=navy]With[/COLOR]
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Thanks for the reply Mick, your approach does the job with code but I'm actually looking for a solution with powerpivot (expecially writting the DAX part to display the custom "total sphere")

But, nevertheless, I appreciate your effort and help!

Anyone else got clues on how to achieve this?
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,629
Members
449,241
Latest member
NoniJ

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