Filter by/Aggregate multiple columns in Power BI - group-by

I would like to group by item and count for each store how many rows are there for my sales data.
table:
Id Item Store Qty
1 A store1 5
2 B store1 2
3 A store2 3
4 B store2 10
....
To group by item I tried:
groupby_item = SUMMARIZE(table, table[Item], "Count", COUNT(table[Item]))
which gives the table:
Item Count
A 2
B 2
but I want to introduce a Store slicer in a visual and I couldn't because Store column is absent in the aggregated table. Can I group by Store then by item and count?
Like in Python you could maybe do:
table.groupby('Item').agg({'Store': 'first', 'Id': 'count'})
to keep the Store information by keeping the first value of Store in each item group.
Would you be able to do that in Power BI? Or is there a better way to do this?

Why create an aggregate table in the first place? You can use the base table in the visual and it would reflect any filters on Store.
The default behavior of PBI visuals is to group categorical columns and aggregate numerical ones.

Related

Tableau - Related Data Source Filter

I have data split between two different tables, at different levels of detail. The first table has transaction data that, in the fomrat:
category item spend
a 1 10
a 2 5
a 3 10
b 1 15
b 2 10
The second table is a budget by category in the format
category limit
a 40
b 30
I want to show three BANs, Total Spend, Total Limit, and Total Limit - Spend, and be able to filter by category across the related data source (transaction is related to budget table by category). However, I can't seem to get the filter / relationship right. That is, if I use category as a filter from the transaction table and set it to filter all using related data source, it doesn't filter the Total Limit amount. Using 2018.1, fyi.
Although you have data split across 2 tables they can be joined using the category field and available as a single data source. You would be then be able to use category as a quick filter.

Pivot Charts in google Sheets by counting non-numeric data?

I have a dataset that I'd like to summarize in chart form. There are about 30 categories whose counts I'd like to display in a bar chart from about 300+ responses. I think a pivot table is probably the best way to do this, but when I create a pivot table and select multiple columns, each new column added gets entered as a sub-set of a previous column. My data looks something like the following
ID Country Age thingA thingB thingC thingD thingE thingF
1 US 5-9 thB thD thF
2 FI 5-9 thA thF
3 GA 5-9 thA thF
4 US 10-14 thC
5 US 10-14 thB thF
6 US 15-18
7 BR 5-9 thA
8 US 15-18 thD thF
9 FI 10-14 thA
So, I'd like to be able to create an interactive chart that showed the counts of "thing" items; I'd then like to be able to filter based upon demographic data (e.g., Country, Age). Notice that the data is non-numeric, so I have to use a CountA to see how many there are in each category.
Is there a simple way to display chart data that summarizes the counts and will allow me to filter based on different criteria?
The query can summarize the data in the form you want. The fact that you have "thA", "thB", etc, instead of "1" complicates the matter, but one can transform the strings to numeric data on the fly.
Assuming the data you've shown is in the cells A1:I10, the following formula will summarize it:
=query({B2:C10, arrayformula(if(len(D2:I10), 1, 0))}, "select Col1, Col2, count(Col3), sum(Col3), sum(Col4), sum(Col5), sum(Col6), sum(Col7) group by Col1, Col2", 0)
Explanation:
{B2:C10, arrayformula(if(len(D2:I10), 1, 0))} creates a table where the first two columns are your B,C (Country, Age) and the other six are filled with 1 or 0 depending on whether the cells in D-I are filled or not.
select Col1, Col2, count(Col3), sum(Col3), ... group by Col1, Col2 selects Country, Age, the total count of rows with this Country-Age combination, the number of rows with thingA for this Country-Age combination, etc.
the last argument, 0, indicates there are no header rows in the table passed to the query.
It's possible to give labels to the columns returned by the query, using label: see query language documentation. It would be something like
label Col1 'Country', Col2 'Age', count(Col3) 'Total count', sum(Col3) 'thingA count', ...
Add a Count column to your data with a "1" for whatever occurrence, this might solve your problem in the Pivot Table. I was just looking for a solution and thought about this. Working now for me.

Give rank using field values on table in Talend

Right Now, I have 8 tables that needs to transform into 1, and I need to add Rank to the Output Table.
By using, Amount Collected field from 1 of the 8 table.
Sample:
Table A: amount_assignment
Table B: amount_collected
OutputTable: Rank= 1 (based on the highest collected)
How can I place 1, 2, 3.... on the Output Table field Rank based on the computed 'amount_collected'?
you can try to use your inputdataflow-->tSortRow-->tMap. In tSortrow you can sort data based on amount column you need and then further in tMap you can put a sequence number to every row using Numeric.sequence("sequencename",1,1) in expression for rank_column

How do I use the result of a grouping count as a top level dimension?

Total Tableau newbie here. I have a dataset that looks like this:
item1
item1
item2
item1
item5
item2
item5
item6
I would like to use the number of times that items appear in this list as a dimension, and count how many of the identifiers in the list occurred that many times. As in:
Items with 1 Occurrrence: 1
Items with 2 Occurrences: 2
Items with 3 Occurrences: 1
In SQL I would do it this way:
SELECT IDAppearsTimes, COUNT(*) AS IDCount
FROM (SELECT Identifier, COUNT(*) AS IDAppearsTimes
FROM DataSetTable
GROUP BY Identifier) AS Data
GROUP BY IDAppearsTimes
Just drag the same var to "Text" mark card, and turn it to Measure-Count
Unfortunately Tableau does not support operations that involve creating a temporary table, such as your Data table. Not in an automatic way.
So, you have 3 options
1) Do the query, create the table and import it in Tableau
SELECT Identifier, COUNT(*) AS IDAppearsTimes
FROM DataSetTable
GROUP BY Identifier) AS Data
2) If your query is slow in SQL (if you have a large table, for instance), Tableau may be faster. And you should:
Drag items and COUNTD([Number of Records]) to a sheet. This will create basically your Data table
Export it (to mdb or csv)
Connect to this new table, extract (extracts are always faster and more compressed)
Profit
3) Take the query in the first option and use it to create a view in your underlying database. Then connect Tableau to that view.
Regards

Merge Row Group Values in SSRs

Is there any ways to merge row group values.suppose Department rowgroup display 3 values Accounts,IT and Finance,both Finance and Account has the same constant values falls within.My problems when run the reports both a divided into different row cells but have same values.want both to combine into 1 row, so matrix table can have only 2 rows
Instead of grouping on Department, i.e.
=Fields!Department.Value,
group on a expression that will return the same value for Finance and Account, e.g.
=IIf(Fields!Department.Value = "Accounts" or Fields!Department.Value = "Finance", "Accounts-Finance", Fields!Department.Value).
In the above example this will give two groups, Accounts-Finance and IT, instead of the three original groups.
Similarly, you could add this expression as a calculated field to the Dataset being used, then group on the calculated field. This is the same approach but will move the logic out of the matrix so it can be used elsewhere in the report.