count rows with duplicate values and group by multiple columns using PowerBI DAX - powerbi-desktop

Dose anyone know how to count rows with duplicate values and group by multiple columns using PowerBI DAX? Below is the example, how to generate the row count by name and group? Thank you in advanced.
Data source table1:
Expected table:

If you need a new table, not just a measure then try this:
NewTable = summarizecolumns(
table1[name]
,table1[group]
,"row count", calculate( COUNTROWS (table1))
)

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.

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

Power Pivot / DAX - Distinct Count of one dim column from multiple fact tables

Using Power Pivot in Excel 2016
I have one dim table called "Roster" with 218 unique 'Employee Names' and other attributes for the employees
I have three fact tables called "Forecast," "Actual," and "Invoice," each with the related 'Employee Name' columns, in addition to many other attributes and values. I want a distinct count of 'Employee Name' across all three of those tables, depending on what I'd like to pivot them by in my pivot table, like 'Project' or 'Company.' I've read about counting across multiple columns from one table, but I'm trying to count across multiple tables.
When I create measure of:
Headcount:=calculate(DISTINCTCOUNT('Roster_Table'[Employee Name]),'Actual','Forecast','Invoice'), and throw it in my pivot table, I get a very small count of 14, which is probably the ones that are unique to only one of the three tables.
When I create measure of: Headcount:=DISTINCTCOUNT('Roster_Table'[Employee Name]), I get all 218
The true number should be around 170. Any ideas of how to make this work?
Thanks
Please try the following DAX calculation:
COUNTROWS(
DISTINCT(
UNION(
VALUES('Forecast'[Employee Name]),
VALUES('Actual'[Employee Name]),
VALUES('Invoice'[Employee Name])
)
)
)

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

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