Calculated measure MDX through Pivot Table Excel - 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

Related

Excel Pivot Table with "Measure"

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.

DAX calculated measure in Power Pivot 2016

I have a data model which I use in Excel 2016 Power Pivot. Here is a simplified version of the fact table and dimension table:
I am trying to calculate a calculated measure that sums the Amt from the Group field. For example, if I am filtered on subgroup 1, I would like the measure to show me '21' which is the sum of Group 'A'.
I have tried the following:
Measure =
CALCULATE(
SUM(FactTable[Amt]),
FILTER(DimesionTable,DimensionTable[Subgroup]=MAX(DimensionTable[Subgroup]))
)
But I get an error saying Max can only be applied to numeric values. How can I create this measure in Power Pivot 2016?
Use this code
Measure =
CALCULATE(
SUM(FactTable[Amt]),
ALLEXCEPT(DimensionTable,DimensionTable[Group])
)

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.

Power Pivot "dynamic" joins

I have a situation where I kind of need a many-to-many join - which I know isn't possible.
I have one fact table and two dimension tables.
The fact table contains account numbers (as in GL accounts) and amounts. Plus a date field, so the account numbers are not unique.
The first dimension table has just one column listing the reports that can be created by combining the accounts in different ways.
The second dimension table could be called a "roll-up" table. It has 3 columns: report, account, and a line item description field. The latter defines which line on the respective report that the account should be mapped to.
So I want to have a pivot table that has the line item description in the row area and the amount in the values area. With a mechanism for the user to specify which report they want to view. But the join on the account field between the roll-up table and the fact table is many-to-many. If the roll-up table were somehow filtered based on the specific report that the user has selected, THEN it would become one-to-many. Hence the "dynamic" joins in my title.
I've been trying to come up with a connecting table of some kind, but without any luck so far. If anybody has any suggestions/pointers, that would be much appreciated.
I figured out a way to do it using a DAX formula that calculates the field to be placed in the Values area. It uses FILTER and CROSSJOIN combinations to effect the dynamic joins. Note that in order to use a CROSSJOIN I added prefix letters to a couple of the field names (to make them unique). Also, I made it that the Report table (the first dimension table I described) has only one row - containing the report that the user wishes to view.
The DAX formula is as follows:
SUMX (
FILTER (
CROSSJOIN (
fBalances,
FILTER (
CROSSJOIN (
dRollUp,
dReport
), dRollup[Report] = dReport[uReport]
)
), fBalances[fAccount] = dRollUp[Account]
), fBalances[Amount]
)
Subsequent update: I moved it into Power BI where I added a parameter (called myReport) for the user to specify the report. Consequently I deleted the dReport table.
So the Power BI DAX formula becomes:
SUMX (
FILTER (
CROSSJOIN (
fBalances,
FILTER (
CROSSJOIN (
dRollUp,
myReport
), dRollup[Report] = FIRSTNONBLANK ( myReport[myReport], TRUE() )
)
), fBalances[fAccount] = dRollUp[Account]
), fBalances[Amount]
)

Resources