Excel Pivot Table with "Measure" - excel

I want to use the pivottable feature of excel to solve my below issue.
I have two tables as follows:
Table= A_Master
Table= A_Child
Where table A_Master Joins with table A_Child on Student Name in pivot table relationship.
The final table has to be like below:
Here I dont know how to create "Measure" = "FeesRemaining" so that it calculates ActualFees-FeesPaid.

If you want the difference between what the actually fee is minus the sum of everything they paid in the other table. Not sure if there is a better way to do it but this is one way to do it.
= CALCULATE(
SUM(Master[Actual Fees]),
FILTER(Master, 'Master'[Student Name] = VALUES('Master'[Student Name]))
) - CALCULATE(
SUM(Child[Fees Paid]),
FILTER(Child,'Child'[StudentName] = VALUES('Master'[Student Name]))
)
The measure above gets a sum of all the fees that are owed by the student in that row of the master table, then subtracts the sum of everything that was paid by that student in the child table.

Related

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]
)

calculate sum with criteria from many columns of another filtered table DAX PowerBi

Hello i want to sum a column but i need to filter the table based on data from another table.
So i have table1 where i want to sum points and i want to sum only the record that for the dates and the names and the classes i find in table 2
I am using measure like this:
Measure 3 = CALCULATE(sum(Table1[points]);Table1[name] in (ALLSELECTED(Table2[name]));Table1[date] in (ALLSELECTED(Table2[date]));Table1[class] in (ALLSELECTED(Table2[class])))
but it does not filter properly,
is there any better way to do this?
One way would be, you create a relationship between the two tables. I think Power BI doesnt support multi relationships between two tables, so you have to add a custom column on both tables with your key <> foreign key. In your case like you mentioned it woulb be the name, date and class (in the query editor):
Key = [name] & [date] & [class]
In my sample here I just use the name as key column.
If the relationship is set you can use the following measure:
You can use TREATAS to filter Table1 based on Table2. No relationship is needed.
Total Points Filtered By Table2 =
CALCULATE (
SUM ( Table1[point] ),
TREATAS (
SUMMARIZE ( Table2, Table2[name], Table2[date], Table2[class] ),
Table1[name], Table1[date], Table1[class]
)
)

How to calculate the daily warehouse stock in DAX?

I have a table in SSAS tabular mode that shows how individual pieces of products moved through different sections of a production line:
Product_ID, section_ID, Category_id (product category), time_in (when a product entered the section), time_out (when the product exited the section)
This is how the input table looks like:
I would like to write a measure in DAX that can show me the stock of each section and product category day-by-day as shown below by counting the number of distinct product ids which were in a particular section on that day.
I'm using SQL Server 2017 Analysis Services in Tabular Mode and Excel Pivot Table for representation.
Create a new table that has all of the dates that you want to use for your columns. Here's one possibility:
Dates = CALENDAR(MIN(ProductInOut[time_in]), MAX(ProductInOut[time_out]))
Now create a measure that counts rows in your input table satisfying a condition.
ProductCount =
VAR DateColumn = MAX(Dates[Date])
RETURN COUNTROWS(FILTER(ProductInOut,
ProductInOut[time_in] <= DateColumn &&
ProductInOut[time_out] >= DateColumn)) + 0
Now you should be able to set up a pivot table with Category_id on the rows and Dates[Date] on the columns and ProductCount as the values.

relationship filter in powerBI or powerpivot

i am using the powerBI tools (powerpivot) to create a data model. i am done the model. the model include the product, customer dimensions and sales fact table. i have made the relationship and hierarchy in the model. now i have a requirement to show the total revenue of all the customer who brought product 1,2,3.
for example customer A brought product 1 and product 5 and the total revenue from this customer is 50 so i want to show 50 as a result
customer B bought product 4 and i do not want to include this customer in my output.
i can do the same in microstratergy using relationship filter but how can i do the same in powerpivot or powerview or powerBI.
Please help
Thanks in Advance
In PowerPivot, relate Sales table with Customer table (Lookup table) and Relate Sales table to Product table (Lookup table).
Create following two measures
[HasPurchased X Products] =
OR (
OR (
CONTAINS ( Sales, Sales[ProductID], 1 ),
CONTAINS ( Sales, Sales[ProductID], 3 )
),
CONTAINS ( Sales, Sales[ProductID], 5 )
)
[DesiredMeasure] =
IF (
Sales[HasPurchased X Products] = TRUE (),
SUM ( [Amount] ),
BLANK ()
)
Select Customers in ROWS and add [DesiredMeasure] in VALUES, pivot table will show desired result.
Additionally to what Abhijeet said, which is a nice robust solution, you might also just filter the chart in Power View. Assuming you have a relationship between sales and products table, you can select the chart in Power View, open the Filters pane, select per chart filters, add Product to the chart filters and filter to include only productions 1,2,3. This will automatically calculate the measure. Now Abhijeet's solution is better if you need that calculation to be reused. This solution works great if you're in a 'what if' scenario where you'd like to say "what are the sales for products 1,2,3" and in another breath say "actually i'm interested in sales for products 2,3 only, so me that instead.".
HTH,
-Lukasz
http://dev.powerbi.com
http://blogs.msdn.com/powerbidev

Calculated measure MDX through Pivot Table Excel

I am connected to OLAP cube, I created a pivottable.
I would like to know if with the OLAP tool of excel is possible to calculate the number of distinct invoice number taking acount the current filters like year, country and region of the pivot table ?
I tried with Countdistinct it gives me the same result for each country.
DistinctCount([PO TYPE].[PO NUMBER].[PO NUMBER])
Try using COUNT instead:
Count(
Exists(
[PO TYPE].[PO NUMBER].[PO NUMBER].MEMBERS,
[Geography].[Country].CURRENTMEMBER,
"MeasureGroupName"
)
)
You need to replace "MeasureGroupName" with a measure group name in your cube

Resources