Sum columns in Power BI matrix - excel

I am working on a matrix in Power BI and I am not figuring out how to sum each column recursively until the total:
And this should be the resulting matrix (as an example, rows):
Some clarifications:
The months (columns) are dynamically generated based on the transaction month. I could filter the data to get the same data for only three months.
"Nombre proveedor" stands for "Vendor name".
I don't care about "Total" row.
These are my values:
So, I think I should create a measure with DAX to replace "Accounting Balance" to sum the previous column (month) or show nothing (to avoid zeroes).
Searching on internet I found several sites to get the running totals by rows, but not by columns.
Any suggestions?

Try Something like this:
Maesure =
CALCULATE (
[Accounting Balance],
FILTER (
ALL ( 'table' ),
'table'[Transaction month] <= MAX ( 'table'[Transaction month] )
)
)

Related

Calculate monthly efficiency in power pivot

I am very new to this power pivot and dax Commands ,kindly help me out here
my sample table looks like this :
Now to calculate monthly efficiency i need to make a measure which satisfies below criteria:
Sum the efficiency for each distinct date & divide by the count of distinct dates for the month
so far for days my below formula is working , but when i group the date into month it is only showing the sum, so kindly help me how to achieve this ;
Actual Efficiency CL2:=CALCULATE(SUM(CL1[Day Wise Efficiency]),DISTINCT(CL1[Date (dd/mm/yy)]))
Divide part is not in your formula, below DAX might help:
Actual Efficiency CL2 :=
DIVIDE (
CALCULATE ( SUM ( CL1[Day Wise Efficiency] ) ),
CALCULATE ( DISTINCT ( CL1[Date (dd/mm/yy)] ) )
)
Note that DISTINCT ( CL1[Date (dd/mm/yy)] ) is not required in the sum as dates in rows will be unique.
To Divide the sum at month level DISTINCT ( CL1[Date (dd/mm/yy)] ) is required as we need how many days a month has.
At day level there will always be 1 to divide by.
Thanks

Need to find the average of all values in pivot table

I have a data table that is pulling all successful contacts by case manager over a period of time. We've created a pivot table of the data that groups by case manager for the rows and by month of the contact for the columns. It counts the appointment IDs to get counts per case manager per month.
My manager wants this data displayed in a chart to easily visualize the data. The part I can't get is she wants the average contacts per month over all the case managers and all the months to be displayed on the chart. Essentially, she wants the average of all the values in the pivot table.
I've played around with power pivot and the DAX functions averagex() and summarize() to get averages in the total row per column, but the ultimate grand total is still the average of the totals.
How can I get the average of all the fields by itself?
Here is the sample pivot table with the totals per case manager per month
Here are the totals using averagex(summarize()) to get counts for the values and average for the totals.
AVERAGEX ( SUMMARIZE ( Table1, [Caseload], "x", COUNTA ( [Client ID] ) ), [x] )
However, the real average I want to see is 34 (all the values averaged together
You need to summarize by month as well to be able to average the way you want.
avg_count =
AVERAGEX (
SUMMARIZE (
Table1,
Table1[Caseload], --Assuming this is what you have on the rows
Table1[Month], --Assuming this is what you have on the columns
"x", COUNTA ( Table1[Client ID] )
),
[x]
)

I need a pivot table of the pivot table I've created

I have a fact table that covers several weeks of tasks in MS Project, and each week is timestamped with that week's week-ending date. I am trying to get the previous week's remaining work for certain tasks (they have a flag called Should Finish This Week set to TRUE).
I have a formula that enables me to create a pivot table that, when I manually sum the values column (it's basically a MIN of the previous week's remaining hours by assignment id), it gives me the result I want.
However, I cannot figure out how to "build this pivot table in DAX" so that I can summarize the resulting sum of hours by department. Right now, I just have the number of hours by task (assignment id) for last week.
Here's the formula:
Simple Min :=
CALCULATE (
MIN ( DataMerge[PreviousWeekRemainingWork] ),
AssignmentHistory[ShouldFinishThisWeek] = TRUE (),
DataMerge[BestPercentComplete2] < 1,
DataMerge[CompletedFLAG] = FALSE (),
USERELATIONSHIP ( 'Calendar'[Date], DataMerge[End of Week] )
)
And with that formula, I can output the following pivot table (this is just a small sample):
The desire is to get a SUM of the Simple Min value by Department. I've tried all the tricks of PowerPivot that I know. Here' the latest iteration of a formula I tried, but the amounts by department are all incorrect, and the grand total is off by about 1200 to the high side.
HRS Remaining More Simple :=
SUMX (
SUMMARIZE (
DataMerge,
DataMerge[ResourceDepartments_R],
DataMerge[AssignmentId]
),
[Simple Min]
)
Any help on this last formula would be greatly appreciated. When I manually sum the pivot table, I come up with ~4300 hours, which is the correct number, so I can verify the formula once given.
Thanks!

DAX average including zeroes

My question is that I'd like to calculate a daily average taking into account days with zeroes.
Let me clarify it:
I'd like to calculate the average daily value of units for each category, with the following table:
When I sum up the values for each day and category, I get:
I'd like to include in the average calculation the zeroes.
I use the following code:
SUMMARIZE(
Data,
Data[Category],
"Average",
AVERAGEX(
SUMMARIZE(
Data,
Data[Date],
"Sum of Units",
SUM(Data[Units])
),
[Sum of Units]
)
)
But the problem is that for category B it doesn't take into account those days with 0s.
Could you please guide me how to solve it?
Thanks in advance!
Jorge
One way to solve it would be to create a calendar table, which can then be used to count the number of days in any of your grouping periods. This also means you can use non standard calendars, for example something like a 4-4-5
With a calendar table created you can leverage the FIRSTDATE and LASTDATE functions in DAX.
I recommend adding a past dates column to the calendar table, which can be created using DAX with the following formula. The today function in DAX when used in a calculated column will only evaluate when the model is updated.
In my example I created a calculated column in the date table called Past_Dates
Past_dates =IF( TODAY() > [Date], TRUE(), BLANK())
So for example if I create the following measures, the Today one just being used for illustration.
Start_date:=FIRSTDATE( Dates[Date] )
End_Date:=LASTDATE( Dates[Date])
Today:=TODAY()
EndPhased:=CALCULATE( LASTDATE( Dates[Date] ), Dates[Past_dates] = TRUE())
Which when added to an empty pivot table evaluate to the following.
Note that you would want to have year somewhere in the pivot if you have multiple years of data.
The idea of having the Past flag is to keep from counting days where they would not be any data due to being in the future. So for example in September it would only use 11 days of sales and not the full 30.
As the below example shows, the finding of the start and end date even work on a Quarter basis.
So now that we have a way to get the Start and End date of a period, the next step is adding it into our Calculated measure.
In the below example, we are iterating though every unique Category name. Within the category, we are summing the units sold, and then dividing by the number of days between EndPhased and Start_Date + 1. Then averaging the results by the number of categories that have data in that period.
Average:=AVERAGEX (
VALUES ( Data[Category] ),
CALCULATE ( DIVIDE ( SUM ( Data[Units] ), [EndPhased] - [Start_date] + 1 ) )
)
It seems to me that you need to have an underlying row with the zero value in it (in your initial Data table). Right now, you don't actually have a zero value for B on 02/01/2017. If you add a row with the values | 02/01/2017 | B | 0 | I believe you will see that the average accounts for it. As things stand for you right now, I believe the pivot table actually reflects no value (blank) rather than zero value, so the zero isn't currently counted for the average.
I think the best way is to add the missing zeroes, using UNION function:
SUMMARIZE(
Data,
Data[Category],
"Average",
AVERAGEX(
UNION(
SUMMARIZE(
Data,
Data[Date],
"Sum of Units",
SUM(Data[Units])
),
ADDCOLUMNS(
EXCEPT(
ALL(Data[Date]),
VALUES(Data[Date])
),
"Sum of Units",
0
)
),
[Sum of Units]
)
)

How to have a measure lookup a value based on the row and column context?

I need to Aggregate a number of multiplications which are based on the Row and Columns context. My best attempt at describing this is in pseudo-code.
For each cell in the Pivot table
SUM
Foreach ORU
Percent= Look up the multiplier for that ORU associated with the Column
SUMofValue = Add all of the Values associated with that Column/Row combination
Multiply Percent * SUMofValue
I tried a number of ways over the last few days and looked at loads of examples but am missing something.
Specifically, What won't work is:
CALCULATE(SUM(ORUBUMGR[Percent]), ORUMAP)*CALCULATE(SUM(Charges[Value]), ORUMAP)
because you're doing a sum of all the Percentages instead of the sum of the Percentages which are only associated with MGR (i.e., the column context)
Link to XLS
One way of doing that is by using nested SUMX. Add this measure to ORUBUMGR:
ValuexPercent :=
SUMX (
ORUBUMGR,
[PERCENT]
* (
SUMX (
FILTER ( CHARGES, CHARGES[ORU] = ORUBUMGR[ORU] ),
[Value]
)
)
)
For each row in ORUBUMGR you will multiply percent by ....
the sum of value for each row in Charges where ORUBUMGR ORU is the same as Charges ORU. Then you sum that product.

Resources