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

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 %

Related

Calculating the representative/average group of categorical data

I have a summary dataset below with 3 variables:
Rating
Frequency
Total Value
A
2
$10000
B
15
$24003
C
5
$56789
...
There are 18 different rating categories each with varying frequencies and values. I need to workout the average group which the data falls into so which of the rating groups is the average in both frequency and total value, so in short the data is rating group B for example.
I'm sure there must be a proper way to do this but haven't been able to easily find the answer online.
I've tried calculating some kind of weighted average but struggling as each category would be equally weighted?
In Office 365 you could use:
=LET(range,A2:C4,
rating,INDEX(range,,1),
freq,INDEX(range,,2),
total,INDEX(range,,3),
w_avg,SUMPRODUCT(freq,total)/SUM(freq),
delta,BYROW(total,LAMBDA(t,
MAX(t,w_avg)-MIN(t,w_avg))),
INDEX(rating,XMATCH(MIN(delta),delta)))
It requires the three columns as an input and names the columns. Than it calculates the weighted average as in my comment.
Then it checks the difference between the total and the weighted average per row. Than it indexes the rating and matches the one with the smallest difference (closest match to weighted average).
Note: in case of ties this would result in the first listed as a result. Otherwise we need to use FILTER.
For older Excel I have a solution including a helper cell & column:
In cell E2 use: =SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4) to calculate the weighted average.
In cell D2 use: =MAX(C2,$E$2)-MIN(C2,$E$2) and drag this down to the last used row in your range to calculate the difference between the total of the rating and the weighted average.
In cell F2 use: =INDEX(A2:A4,MATCH(MIN(D2:D4),D2:D4),0)
To match the rating of the smallest difference.
Or this one line monster:
=INDEX(A2:A4,
MATCH(
MIN(
IF(C2:C4>=SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4),
C2:C4,
SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4))-
IF(C2:C4<=SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4),
C2:C4,
SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4))),
IF(C2:C4>=SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4),
C2:C4,
SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4))-
IF(C2:C4<=SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4),
C2:C4,
SUMPRODUCT(B2:B4,C2:C4)/SUM(B2:B4)),
0))

EXCEL Sumifs to PowerBI

I have a formula in Excel that gives me the sum of several cells if two conditions are met.
In Excel, the base has been converted into a table so that this works.
The formula is as follows:
=sumifs(B:B,B:B,">0",A:A,"<="&[# month])
In A I have sales and in B the month. If I have sales in A that are greater than 0, it should add up all sales for the months if the month of the line is less than or equal to the own month.
In Power BI, it only sums up all months from start to finish if the value is greater than 0, but not the amount of sales for the one month.
month
sales
sumifs
1
500
737
1
237
737
2
420
1157
3
380
1537
4
410
2437
4
280
2437
4
210
2437
5
0
2437
just create a new measure (or calculated column).
Sumif = SUMX('Tablename','Tablename'[sales])
try this:
Measure 2 = CALCULATE( sum(Table[sales]), FILTER(ALL(Table), Table[month] <= SELECTEDVALUE(Table[month])))
If you want to have the result as a separate column, you can do it with two queries:
Load_Data
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content]
in
Source
Calc_Sum
Group by month and sum up sales to get result per month
Add original data via month and show sales column to re-include the original sales
Rearrange the columns in case the order is relevant for you
let
Source = Load_Data,
Group = Table.Group(Source, {"month"}, {{"Sum_of_sales", each List.Sum([sales]), type nullable number}}),
AddOriginalData = Table.NestedJoin(Group, {"month"}, Load_Data, {"month"}, "Load_Data", JoinKind.RightOuter),
ShowSales = Table.ExpandTableColumn(AddOriginalData, "Load_Data", {"sales"}, {"sales"}),
Rearrange = Table.ReorderColumns(ShowSales,{"month", "sales", "Sum_of_sales"})
in
Rearrange
Try this Dax in a Calculated Column. It worked for me with your Data
SUMIF = CALCULATE(
SUM(Table[Sales]),
FILTER(ALL(Table), Table[Month] <= EARLIER((Table[Month]))),
Table[Sales] > 0
)
Do let me know if it worked for you.
Have a good day !!
Best Regards,
Pratik

DAX - referencing row header in a formula

I need your help in creating a DAX measure that would help me resolving the following problem:
I have a table that shows case number, creation date and closure date:
case_number creation_date closure_date
CA001 4/15/2020 4/19/2020
CA002 4/17/2020 4/20/2020
CA003 4/19/2020 4/21/2020
CA004 4/19/2020 4/20/2020
I have a pivot with various measures where row headers are consecutive days from a related Calendar table. One of the columns I need is a number of active cases in given day (number of cases that were created before or the same day as the context date, AND closed after the context date). The expected outcome would be like this:
date open_cases
4/13/2020 0
4/14/2020 0
4/15/2020 1
4/16/2020 1
4/17/2020 2
4/18/2020 2
4/19/2020 3
4/20/2020 1
4/21/2020 0
in regular Excel, the formula that calculates the same would be =COUNTIFS(table_cases[creation_date],"<="&[#date],table_cases[closure_date],">"&[#date]), but in my case this will be a part of a bigger pivot table/dashboard and I need to write a measure in DAX that would calculate this.
I would appreciate your help in this matter.
Best regards,
Michal
There are a variety of ways to read the current context. You can use MAX or VALUES or SELECTEDVALUE (if available). These don't all behave exactly the same, so use whichever is appropriate for your situation.
open_cases =
VAR RowDate = MAX ( Calendar[date] )
RETURN
CALCULATE (
COUNT ( table_cases[case_number] ),
table_cases[creation_date] <= RowDate,
table_cases[closure_date] > RowDate
)
Here, MAX is evaluated within the filter context, so it should return the value in the current row (or the maximal date for subtotals and grand totals).

Grand total for pivot table not giving me the correct amount when using a calculated field

I have a pivot table that I put a calculated field in. the calculation is =IF(fddue_date<finspectData,0,COUNT(fLotSize))
The problem is that instead of getting the expected result of 6 I get 1. Any one have an idea what I am doing wrong?
Row Labels Count of fLotSize Sum of Field1
5/14/2014
5/12/2014 1 0
5/14/2014 7 1
5/15/2014 9 1
5/16/2014 5 1
5/19/2014 3 1
5/30/2014 1 1
6/9/2014 1 1
Grand Total 27 1
This is a side effect of the calculated field and it treats the grand total the same way as any other row in the pivot table.
If you want to use this type of calculated formula and have a sum shown in the grand total, the best way is to create the formula in the source data table and then pull it into your pivot table as a separate column which will show the correct grand total.
it's by the way a known bug since at least Excel 2003. still in 2013 ...
https://support.microsoft.com/en-us/kb/211470

Split a percentage over 3 fields?

I've got 3 cells in my spreadsheet that have the layout as below. These values are dynamic, however what I need to do is split a percentage over the 3 fields, and then increase the number.
Total Staff Costs £1,000.00
Total Hardware Costs £0.00
Total Expenses £400.00
For instance, the above comes to a total of £1400, however I need to charge 10% of my own time on top of this so £140.
What I can't just do though, is take this 10% and split it over the 3 fields, ie. I can't just add £46.70 to each field, because no hardware has been bought, so to say its £46.70 would raise some questions. I need to split it proportionally between each one.
How can I go about adding X% to the fields proportionally?
Wouldnt the logic be to determine the percentage of the total for each field. Then multiply that percentage by the total of the 10%
so you have 3 fields totalling 1400
so 1000 / 1400 = .714286
so 0 / 1400 = 0
so 400/ 1400 = .0285714
now multiply these by the totals
so 1400 * .714286
so 1400 * 0
so 1400 * .0285714
These should total to the 10%
so all your data is in Column b in cells 1, 2, 3
The formula that would go in to the cells C1, C2, C3 (assuming you want these totals in the next column over)
=(B1/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C1
=(B2/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C2
=(B3/SUM($B:$B)) * (SUM($B:$B)*0.1) 'Cell C3

Resources