How do you calculate a field from calculated fields.

alex1alex

Board Regular
Joined
Sep 12, 2014
Messages
57
Hello everyone,

I need to Aggregate a number of multiplications which are based on the Row and Columns. My best attempt at describing this is in pseudo-code.

Code:
[FONT=Calibri] 
[/FONT][FONT=Calibri]For each cell in the Pivot table[/FONT]
[FONT=Calibri]    SUM[/FONT]
[FONT=Calibri]       Foreach ORU [/FONT]
[FONT=Calibri]                  Percent= Look up the multiplier for that ORU associated with the Column[/FONT]
[FONT=Calibri]                  SUMofValue = Add all of the Values associated with that Column/Row combination[/FONT]
[FONT=Calibri]                  Multiply Percent * SUMofValue
[/FONT]

I tried a number of ways over the last few days and looked at loads of examples but am missing something.


I have an example XLS here from my onedrive: link
With some screen grabs below.
At the bottom is what I'd like the pivot table to look like.

Any help would really be appreciated.

Kind Regards,
Alex


2HC7Lk7.png


KK3b61v.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Looking at this some more....the hurdle is that I want to use the context of the column as part of my calculated column. So, in my example, MGR is the column, but I have no way to look up that column for the filter (which I would then use to lookup the percent in the ORUBUMGR table).

Can you use/lookup the column context?
 
Upvote 0
I have to admit, that's a cool page and I'll be using that!

But for this question....I think I have a 1:0 relationship (I don't even know what to call it...maybe that's my problem.)

If you look in the data model, the MGR only shows up in one data table...and i put it in the Column of the pivot table.
For the calculated item, I need to say, "look up my MGR, and get the associated Percent"
(then do some multiplication)

The Magic measure seems to require that the MGR be in a couple of tables.... NO?

I appreciate the help!
 
Upvote 0
Well, yes model looks a bit strange, but at least in my eyes you have a m2m-relation between charges and ORUBUMGR, with the necessary Bridge table (ORUMAP) in between.

So sth like: CALCULATE(SUM(ORUBUMGR[Percent]), ORUMAP)*CALCULATE(SUM(Charges[Value]), ORUMAP) should give the desired result.

But having a look at it: only if you actually use the ORU field in your Pivot Report (you need that filter context). That's at least not the case in your example - so unfortunately this might not work here - sorry.
 
Upvote 0
Yes, that was my 1st try as well but the operator order is wrong.

I need a:
SUM ( Percent * Value )
where as that example is doing:
SUM ( Percent ) * SUM (Value )

To be clear, I do use the ORU field I the Pivot Report but as part of the calculated field. (which we're talking about....if that makes sense.)
Regarding the m2m, yeah, I see what you mean...the ORU is M2M with the bridge....it's the MGR that is the 0-to-1 :(

Thanks for you attempt :)
 
Upvote 0
Hi Alex,
This is really weird, but it works - let's hope that a merciful DAX expert catches this and tidies up :)

Everything happens in ORUBUMGR:

1) Create a calculated column: =[ORU]&[MGR]

Giving you the desired granularitiy-level for your %-values (line-basis, but you need a field that can be referenced, probably a simple index would work as well).

2) Create measure: MValue:=CALCULATE(SUM(Charges[Value]); 'ORUMAP')

Here you apply the m2m-technique to retrieve the Value from the Charges-table

3) Create measure: %:=CALCULATE(SUM([Percent]); FILTER(ALL(ORUBUMGR); COUNTROWS(FILTER(ORUBUMGR; EARLIER(ORUBUMGR[level])=ORUBUMGR[level]))))

This is the weird part: We’re forcing that line-level to stick before we aggregate, even on aggregates levels (as we want to have it this way: SUM ( Percent * Value ) by applying a grouping-technique (on the single line….shame - I’m not that advanced on DAX actually – let’s hope that someone tidies this up…)

4) Create measure: Result:=SUMX(ORUBUMGR; [MValue]*[%])

This is your Sumproduct (SUM ( Percent * Value ) instead of SUM ( Percent ) * SUM (Value))
 
Upvote 0
Hi!

Um. Yeah. It works! I'm beyond excited. If only I understood it :confused:

To clarify, for 1), the calculated column is named [level] { as that's what's referenced in the filter for 3) }

I run across the EARLIER function while looking for a solution but was at a loss as to how I would implement it.

Thanks SO Much!

Kind Regards,
Alex

PS: and that you can use "%" as a name, that's just cool. I've learned a lot from this thread :)
 
Upvote 0
Hi Alex,
These fellows brought nested SUMX into play which gets us rid of the necessity for that additional column:
http://www.mrexcel.com/forum/power-bi/847993-dax-question-weighted-average-across-granularities.html

Combined with some other wisdoms shared in the net (thank you :)) that are elaborately explained here:
MDX and DAX topics: The Logic behind the Magic of DAX Cross Table Filtering (explaining how calculate helps keeping the context)
– we actually end up with a single measure, that looks halfway decent:

ResultS:=SUMX(ORUBUMGR; Calculate(SUMX(ORUBUMGR;[Percent]))*CALCULATE(AVERAGEX(ORUBUMGR;CALCULATE(SUM(Charges[Value]);'ORUMAP'))))

It’s getting into the right direction now, I think :)
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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