In Excel is there a way to show PivotTable count of cells containing a text string? - excel

I have data from a satisfaction survey. One of the questions allows respondents to check up to 5 boxes. The resulting data is a concatenation of the text of all the boxes that were checked, i.e., "box one;box three;box four" or "box two;box five", etc. Need a pivot table to show out of all responses, how many times box 1 was checked, etc. My data is in Table format and I check the box saying "Add this data to the Data Model" when generating the PivotTable. Then I tried adding a Measure to using DAX formula:
[=COUNTAX(Survey,[What most influenced your service satisfaction?]="* box one *")]
to count how many times the text string "box one" appears in the column. I get an incorrect value = it is just returning the total number of rows in the table.

The COUNTAX function counts every row that evaluates to anything non-blank. In your case, the expression evaluates to FALSE() for every row since the asterisks don't act as wild but as literal asterisks so every row gets counted.
How about counting the rows after filtering for ones that contain "box one"?
BoxOneCount =
COUNTROWS (
FILTER ( Survey, CONTAINSSTRING ( Survey[What Influenced], "box one" ) )
)
Edit: The CONTAINSSTRING DAX function is a newer one that doesn't work in Excel. You should be able to use an alternative with FIND for Excel.
BoxOneCount =
COUNTROWS (
FILTER (
Survey,
NOT ( ISERROR ( FIND ( "box one", Survey[What Influenced] ) ) )
)
)

Related

Sum columns in Power BI matrix

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

Sum in pivot hierachy

I have the following DAX-formula to retrieve the opening and closing balance for a list of products.
=CALCULATE(MAX(transactions[Balance]);
FILTER(transactions;
transactions[ID] = MAX(transactions[ID])
)
)
This works on row level in my Pivot but when I group this och Product category level I only get one value and not the sum of all the product rows.
My data contains of rows for each transaction and each row have a columns with current balance.
How do I sum each row to get the group sum for the above category "00-01" 26784 and 283500?
One way to do this is to leverage an iterative function like a SUMX.
Assuming that your EndValue is the measure that you defined.
SUMX_Example := SUMX( VALUES ( transactions[ID] ) , [EndValue] )
Which will do the following:
Though VALUES ( transactions[ID] ) it will generate a list of your IDs
For each ID it will run your already created [EndValue] measure
Sum the result of each ID's end value
This is of course assuming [ID] does not cover categories. If ID does cross categories, then you would first do a SUMX using category, with another SUMX that does ID

Break ties in RANKX Powerpivot formula

I can rank my data with this formula, which groups by Year, Trust and ID, and ranks the Areas.
rankx(
filter(Table,
[Year]=earlier([Year])&&[Trust]=earlier([Trust])&&[ID]=earlier([ID])),
[Area], ,1,Dense)
This works fine - unless you have data where the same Area appears more than once in the same group, whereupon it gives all rows the rank of 1. Is there any way to force unique rank values? So two rows that have the same Area would be given the rank of 1 and 2 (in an arbitrary order)? Thank you for your time.
Assuming you don't have duplicate rows in your table, you can add another column as a tie-breaker in your expression.
Suppose your table has an additional column, [Name], that is distinct between your multiple [Area] rows. Then you could write your formula like this:
= RANKX(
FILTER(Table,
[Year] = EARLIER([Year]) &&
[Trust] = EARLIER([Trust]) &&
[ID] = EARLIER([ID])),
[Area] & [Name], , 1, Dense)
You can append as many columns as you need to get the tie-breaking done.

Sum column based on criteria while grouping in Power Query

I am trying to group a datasheet and return the sum of column a based on values in column b but I still need to return the sum of the complete column c so I can't filter the table prior to grouping.
I just tried this:
Table.Group (
MyTable
, {
"ColumnD"
}
, {
{
"Sum Criteria"
, each List.Sum (
Table.Column (
Table.SelectRows (
_
, each [ColumnB] = "Foo"
)
, "ColumnA"
)
)
, Int64.Type
}
, {
"Sum Complete"
, each List.Sum ( [ColumnC] )
, type number
}
}
)
But the numbers aren't right, in my example the result of the criteria based column should be 15 but it's returning 35.
Can anyone please help me figure out where I am erring?
Thanks
I am really sorry for asking this question, the solution I used initially was right.
my mistake was that I previewed the results by adding another column which contained all rows, and while I was previewing it, I counted them out and found that the numbers didn't match. When I expanded the table many more rows were revealed showing that the formula was accurate.
I wonder what the bug is with the query designer that it didn't show all the rows while previewing the table.
I am leaving the question so other people can see my formula and enjoy it.

Next closest airport in excel which also match specific criteria

I posted a related question here which covers finding the next closes airport in a list which has the airport code, longitude and latitude.
However, I find that I now need to restrict that set of airports by an addtional value in another column.
The formula I'm using is:
=INDEX
(
A$1:A$7184,MATCH
(
MIN
(
IF
(
D1&","&E1<>D$1:D$7184&","&E$1:E$7184,
ABS(D1-D$1:D$7184)+ABS(E1-E$1:E$7184)
)
),
IF
(
D1&","&E1<>D$1:D$7184&","&E$1:E$7184,
ABS(D1-D$1:D$7184)+ABS(E1-E$1:E$7184)
),0
)
)
The data set is comprised of around 7000 rows as per the below sample. I'm attempting to modify the above formula to find the next closest airport which has a '1' in column f. The next closest column contains the formula.
Use MINIFS function :
=INDEX
(A$1:A$7184,
MATCH
(
MINIFS(SQRT(($D$1:$D$7184-D1)^2+($C$1:$C$7184-C1)^2),$E$1:$E$7184;"=1"),
SQRT(($D$1:$D$7184-D1)^2+($C$1:$C$7184-C1)^2),
0
)
)

Resources