Wrong total on measure with IIF - excel

I have a very simple set [Sales Set]:
{
[Accounts Master].[Account Code].&[XXXXX1]
, [Accounts Master].[Account Code].&[XXXXX2]
...
[Accounts Master].[Account Code].&[XXXX20]
}
I ultimately want to create a calculated measure that will get its value from measure Gross Sales when the account is in this set or from an account group I have specified (let's call it Sample Account) and from Net Sales when it is not.
So far I have used the following measure [Sales Measure] to achieve that:
IIF
(
Exists
(
[Sales Set]
,[Accounts Master].[Customer Description].CurrentMember
).Count
= 1
OR
Exists
(
[Accounts Master].[Account Group].&[Sample Account]
,[Accounts Master].[Customer Description].CurrentMember
).Count
= 1
,[Measures].[Gross Sales]
,[Measures].[Net Sales]
)
This does what I want but the total disregards anything that is not in the [Sales Set] or in the Account Group [Sample Account].
This is what happens:
Account Group **Sales Measure** Gross Sales Net Sales
XXXXX1 **20** 20 12
XXXXX2 **45** 45 35
YYYYY1 **15** 25 15
YYYYY2 **30** 40 30
__________________________________________________________
Total **65** 130 92
Everything is as it should except the Total.
In this example the total for Sales Measure should be 110.
Is there a way that I can achieve the same functionality that I have now but also having the total being calculated correctly?
EDIT: On closer inspection the results are like these:
Account Group **Sales Measure** Gross Sales Net Sales
XXXXX1 **20** 20 12
XXXXX2 **45** 45 35
YYYYY1 **15** 25 15
YYYYY2 **30** 40 30
__________________________________________________________
Total **130** 130 92
So it seems that the total of Sales Measure is always the same as the Gross Sales total.

Related

Averaging percentages across filtered groups in Power View

I import data into Excel using Power Query, where I add a new column to calculate a usage percent. I then want to use Power View to visualize this data. However, when applying filters on the data and wanting to view the average usage percent across filters, the results are incorrect as Power View is simply averaging the percentages, rather than calculating the totals of each parameter and applying the formula afterwards. Is there a way to write my formula, so the percentage will be calculated after filters are applied in Power View?
In my example, Usage% = Direct/(Total-Fringe).
Because the denominator is not constant, the usage percent for Group A is not simply an average of the Usage% cells assigned to Group A. The average of Usage% cells in group A is 75%, but the correct usage percent calculated for the Group A using parameter totals is 98/(168-40)= 76.56%. Power View shows the incorrect 75%, as it is simply averaging the cells that correspond to Group A.
I would like to use the filters in Power View to view charts showing usage percent at various levels, including Group and Division, along with other information not shown in the example.
ID Group Division Direct Total Fringe Usage%
1 A AA 40 40 0 1.00
2 A AA 20 40 10 0.67
3 A AB 18 40 15 0.72
4 A AB 20 48 15 0.61
5 B BA 40 40 0 1.00
6 B BA 18 40 12 0.64
7 B BB 12 40 20 0.60
8 B BB 40 48 0 0.83
Create Usage % as a Measure in your Data Model, instead of as a column:
Usage % =
DIVIDE (
SUM ( MyTable[Direct] ),
SUM ( MyTable[Total] ) - SUM ( MyTable[Fringe] ),
BLANK()
)

Returning a value based on multiple criteria and ranges of numbers

I am looking for a way to do some type of lookup/match to come up
with bonuses. It is based on what they sold, for how much, and based on how much they sold last year, and the amount increased.
Example Line 2: So say they sold $900 worth of pens to Joe (New Amount is w/in 1-999). Last
year Joe only bought $23 worth of pens (Previous Amount is w/in 1-24) they get a $25 bonus (Bonus). Also..
There also has to be a minimum increase amount (Min increase column). So say if Joe bought
$999 worth of pens last year and $1000 worth of pens this year, the
salesperson shouldn't get a bonus because it was only a buck increase. It has to be at least $50 increase in this case. That's what the Min Increase column is.
Group Min Increase Previous Amount New Amount Bonus
Min Max Min Max
Pens 50 1 24 1000 999999 45
Pens 50 1 24 1 999 25
Pens 50 25 100 1000 999999 45
Pens 5 25 100 1 999 25
Paper 10 1 24 1000 999999 50
Paper 10 1 24 1 999 25
Paper 10 25 100 1000 999999 50
Paper 5 25 100 1 999 25
I started looking at Indexmatching but it's not enough. Then I thought of summing, but it's really not adding anything together.
=SUMIFS(B3:B10, G1:G10, "Pens", D3:D10, "50")
Also, =INDEX(range2,MATCH(TRUE,COUNTIF(range1,range2)>0,0)) won't work because that's only two ranges.
It also has to be something they can update constantly.
The actual data looks something like this
Sale Prev. Group
900 23 Pens
So you'd need to find the difference, see if it's within the minimum increase for the group and the amounts (900-23 > 50). Then return a value. 23 is between 1 and 24 and 900 is between 1 and 999 so $25 bonus.
Does anyone have any suggestions? I'm looking into index matching, but I can't find out how to do it with ranges.
Thanks
The formula is based on aggregate which performs array like operations. As such keep full column references inside of the aggregate function as short as you can and avoid full column references. Based on the layout of information in the picture above, place the following formula in L3 and copy down as required.
=IFERROR(INDEX(G:G,AGGREGATE(15,6,ROW($A$3:$A$10)/(($A$3:$A$10=$K3)*($C$3:$C$10<=$J3)*($D$3:$D$10>=$J3)*($E$3:$E$10<=$I3)*($F$3:$F$10>=$I3)*((I3-J3)>=$B$3:$B$10)),1)),"No Bonus")
Caveat: If for some reason, the sales situation matches multiple rows in your table, then it will return the bonus corresponding to the lowest row number that met all the criteria.

PowerPivot Grand Total, Sum of all change in %s?

So I am working on a report that has to show total 'pts' in a table based on the performance of certain groups of work.
Right now I have a PowerPivot that Sums Actuals, Forecasts, and the Variance. Then I have separate formulas that filter on each group so that I get a variance % based on each group.
Example formula - 'Group1 Acc:=ABS(CALCULATE(([Actual]-[Forecast])/[Actual],talbe[name]="Group 1"))'
I want the table to look like this....
Column Group 1 Group 2
Criteria 1 25% 25%
Criteria 3 20% 20%
Criteria 4 10% 10%
Grand Total 21.2% 55%
Group 1 is how it is currently working and makes sense to me but isn't doing what I want. It is getting the weighted % change of all the groups. Total Actual-Total Forecast/Total Forecast basically. In this example it comes out to 21.2% because Criteria 4 had a larger % of the total Actual and Forecast for the time period I am comparing.
I want it to work like it is showing in Group 2. The SUM of the total %s over each criteria group. I've tried SUMX formulas, Value(), and such but can't figure this out. Any help would be appreciated.
Thank you!
Check out this article: Subtotals and Grand Totals That Add Up “Correctly”
Basically, you can create logic so that the total behaves separately from the individual rows. Something along these lines:
Measure =
IF(COUNTROWS(VALUES(Table1[Criteria])) = 1,
[Group 1 Acc],
SUMX(VALUES(Table1[Criteria]), [Group 1 Acc])
)
Data:
Type Actual Forcast
Criteria1 33 32
Criteria2 543 345
Criteria3 643 633
Criteria4 45 65
Criteria5 7890 7999
MEASURE 'datatable'[SumOfActuals] =
SUM ( 'DataTable'[Actual] )
MEASURE 'datatable'[SumOfForcast] =
SUM ( 'DataTable'[Forcast] )
MEASURE 'datatable'[Group1] =
DIVIDE (
'datatable'[SumOfActuals],
CALCULATE ( 'datatable'[SumOfForcast], ALLSELECTED () )
In Excel, filter for Criteria 3 and 4
Row Labels Group1
Criteria3 92.12 %
Criteria4 6.45 %
Grand Total 98.57 %

Calculating Total based on Different Discount Rates

I’m trying to calculate the total contract value on a list of projects with different monthly rates and terms (#months). Basically you get a nice discount if the term is longer than 24 months however the discount is capped at $1,000 (you can’t discount more than $1,000)
0-24 months:Full Price
25-48 months:50% of the full price (capped at $1,000)
49 onwards:25% of the full price (capped at $1,000)
Attached is my spreadsheet and the calculated total works well for some monthly rates but the formula doesn’t work well for lower monthly amounts. I have two columns, Calculated Total and Desired Total (what the total should be). Any idea how I can fix the Calculated Total Formula to get the desired total? Thank you
Amount Term Calculated Total Desired Total
1500 68 $74,000 $80,000
1000 48 $36,000 $48,000
4000 36 $120,000 $120,000
3000 30 $81,000 $81,000
2000 27 $51,000 $51,000
4000 120 $216,000 $216,000
NumMonths Base Discount
0 0 1.00
24 24 0.50
48 36 0.25
Formula:
=A2*VLOOKUP(B2,$F$2:$H$4,2)+A2*(B2-VLOOKUP(B2,$F$2:$F$4,1))*IF((A2*VLOOKUP(B2,$F$2:$H$4,3))<1000,1000/A2,VLOOKUP(B2,$F$2:$H$4,3))
In order to get to a solution I changed the setup of your sheet slightly (beginning, end, discount and max. discount):
In order to get to your solution, you just have to multiply the different tiers with the terms for each tier. I used IF functions to do this:
IF(B2>$G$2,$G$2,B2)*IF(A2*(1-$H$2)<$F$7,$F$7,A2*(1-$H$2))+IF(B2>$G$3,$G$3-$G$2,IF(B2-$G$2<0,0,B2-$G$2))*IF(A2*(1-$H$3)<$F$7,$F$7,A2*(1-$H$3))+IF(B2-$G$3>0,B2-$G$3,0)*IF(A2*(1-$H$4)<$F$7,$F$7,A2*(1-$H$4))

Possible to use a running total row in powerpivot for calculation in a calculated field?

If I have a pivot table and I set the row to be a running total according to date and right now i will like to use this row to create a calculated field. Is it possible?
If not then is there a formula for cumulative calculations for calculated field?
Will supply more examples if need more clarification.
I want to do something like this
week 1 2 3 4 5 6 7 8 9 10
count 20 20 21 25 26 27 28 29 21 21
cumulative count 20 40 61 86 112 139 167 196 217 238
If the week is the base field then can I create a calculated field that does something like the cumulative count? I am doing this as i need to use the cumulative count for further calculations and if i use the show values as running total it seems to me that I cant use that variable for further calculations.
Hope this helps to clarify.
There are time intelligence functions built into DAX. You could use TOTALYTD(), TOTALQTD(), and TOTALMTD() if you have a proper date dimension with contiguous, non-repeating dates ranging from January 1 in the first year you have data through December 31 in the last year you have data.
If you have a non-standard fiscal calendar you can get the same effect so long as you have index fields for each time granularity of interest which are increasing over time.
CustomTotalYTD:=
CALCULATE(
[<some measure>]
,FILTER(
ALL( 'DimDate' )
,'DimDate'[FiscalYear] = MAX( 'DimDate'[FiscalYear] )
&& 'DimDate'[Date] <= MAX( 'DimDate'[Date] )
)
)

Resources