Grouping by multiple columns and aggregating all values - powerbi

I am rather new to Power Bi and I have a question i can't find the answer to.
I want to import a table that have some label columns, with repeated items, and more than 15 data columns.
My desire result would be to group the label columns, so no repeated items, and aggregate the values of the remaining columns.
Is there a way to do that in PQ editor or DAX ?
I appreciate any help or direction you can give me!
A sample of the table (it's much bigger, with multiple values in the first three columns)
Table Sample
Thanks a lot
Edit: From that sample, the output y I want is the following
Output Sample
The thing is, there are many different values in the first columns, and i need to agreggate all the other values, keeping they column name (cause this info is already linked to other files).
Maybe the only way is to group by and add the columns, renaming them one by one?
I want to do this in a couple of files, so if you know of another way please let me know!

In your query designer import your table. Then go to Home > Group By and group like you want it, the same goes for the aggregations and thats it.
If you just want to remove row duplicates, just group all columns which you dont want to aggregate and the rest can be aggregated like you want it.

Related

Power Bi dealing with repeated instruments from REDCap

I have data like this:
It comes from REDCap, and as you may be able to tell, the data in the far right columns are repeated variables about each "protocol_title" (the far left column). I.e. "Love it" and "I want a disc instead" are both about "study 2"
I've imported the data into Power Bi and currently I have this:
What I'd like is for the top left visual to only have one row per study (with columns such as principal investigator and method of image transfer, i.e. columns that had data in the first row) and a visual on the lower left with all the right-most columns.
By switching the top visual from a table to a matrix I can kinda accomplish this:
But it adds a bunch of unnecessary columns. As an alternative I thought I could add a filter to the top visual that would filter to "redcap_event_name"=="protocol_information" which would only be those top rows.... but given the visuals are linked, if I do that it removes everything from the bottom visual. I'd like to keep the link between the visuals so that if I select "study2" in the top visual, it'll highlight relevant study 2 information in the bottom one.
So my question is: what's the best approach for making the visuals I want? Are there special settings for visuals? Do I need to do something to the data first in the query? How should I go about this?
You might want to rework you data structure. At first glance, your flat source table could be parsed into two tables :
Protocol
Survey
This can be done in PowerQuery.
For Protocol :
Select columns A to R.
Filter on redcap_event (?) starts by "protocol_info"
Delete empty rows
For Survey
Select columns A (to keep the protocol ID and be able to link both tables), T and U.
Filter on redcap_event (?) starts by "survey"
Delete empty rows.
You should end up with the two table with a one-to-many relationship between Protocol[Protocol_ID] (column A) and Survey[Protocol_ID] (same)
And it should make everything much easier: visuals, calculations...

Is there a way that POWERBI does not agregate all numeric data?

so, I got 3 xlsx full of data already treated, so I pretty much just got to display the data using the graphs. The problem seems to be, that Powerbi aggregates all numeric data (using: count, sum, etc.) In their community they suggest to create new measures, the thing is, in that case I HAVE TO CREATE A LOT OF MEASURES...Also, I tried to convert the data to text and even so, Powerbi counts it!!!
any help, pls?
There are several ways to tackle this:
When you pull a field into the field well for a visualisation, you can click the drop down in the field well and select "Don't summarize"
in the data model, select the column and on the ribbon select "don't summarize" as the summarization option in the Properties group.
The screenshot shows the field well option on the left and the data model options on the right, one for a numeric and one for a text field.
And, yes, you never want to use the implicit measures, i.e. the automatic calculations that Power BI creates. If you want to keep on top of what is being calculated, create your own measures, and yes, there will be many.
Edit: If by "aggregating" you are referring to the fact that text values will be grouped in a table (you don't see any duplicates), then you need to add a column with unique values to the table so all the duplicates of the text values show up. This can be done in the data source by adding an Index column, then using that Index column in the table and setting it to a very narrow with to make it invisible.

Power BI / Power Query - M language - playing with data inside group table

Hello M language masters!
I have a question about working with grouped rows when the Power Query creates a table with data. But maybe it is better to start from the beginning.
Important information! I will be asking for example only about adding an index. I know that there are different possibilities to reach such a result. But for this question, I need an answer about the possibility to work on tables. I want to use this answer in different actions (e.g table sorting, adding columns in group table).
In my sample data source, I have a list of fake transactions. I want to add an index for each Salesman, to count operations for each of them.
Sample Data
So I just added this file as a data source in Power BI. In Power query, I have grouped rows according to name. This step created form me column contained a table for each Salesman, which stores all his or her operations.
Grouping result
And now, I want to add an index column in each table. I know, that this is possible by adding a new column to the main table, which will be store a new table with added index:
Custom column function
And in each table, I have Indexed. That is good. But I have an extra column now (one with the table without index, and one with a table with index).
Result - a little bit messy
So I want to ask if there is any possibility to add such an index directly to the table in column Operations, without creating the additional column. My approach seems to be a bit messy and I want to find something cleaner. Does anyone know a smart solution for that?
Thank you in advance.
Artur
Sure, you may do it inside Table.Group function:
= Table.Group(Source, {"Salesman"}, {"Operations", each Table.AddIndexColumn(_, "i", 1, 1)})
P.S. To add existing index column to nested table use this code:
= Table.ReplaceValue(PreviousStep,each [index],0,(a,b,c)=>Table.AddColumn(a,"index", each b),{"Operations"})

How to add multiple fields in columns of Power BI matrix and view them without drilldown

I've trying out Power BI to solve some visualization problem in my organization and I've been working on desktop version of Power BI to try out its features.
I'm stuck at few issues and cannot find our way out of this.This is a sample view I've been trying to create:
Figure 1:
1
We've a dataset containing Product Opinion across gender, Age Group, Geography etc. and we want to pivot the opinion across different parameters as shown above.But when we use Matrix view of Power BI and add two parameters in columns, it creates a drill down view as shown below:
Figure 2: 2
On adding multiple fields in the column section we get an option to move down to next hierarchy as shown below:
Figure 3:3
Although we have the option to move down to hierarchy ,we are unable to show then side by side as we've shown in Figure 1.
Is there a way we can get the visualization as given in Figure 1 ?
Also, Currently the columns and rows are automatically sorted alphabetically. Is there a way we can adjust the column and row position as per our needs?
To sort the rows in a custom order, you will have to create an index table. The below link walks you through the steps involved:
http://www.excelnaccess.com/custom-sorting-in-power-bi/
Now, to achieve the visualization you are looking for, the only way I can think of is to create two matrix visualizations (One for gender and other for age group) and place them in such a way, that it gives the illusion of the same table. There might be a better way to do this, but I these workarounds work just fine. Hope this helps.

Merge or combine two columns in power bi

I am not sure if my title is correct one, but here is the deal:
I want to make a matrix visualization in Power Bi Desktop. I have fields: ARTICLE_ID and ARTICLE_NAME.
I would like to have both those fields in COLUMNS position in matrix data view. And I need them to be in one row, no need to drill down... because it is one and the same thing...
I need to have ARTICLE_ID and ARTICLE_NAME as two separate columns on the same level. without drilling. And also, I dont want to use concatenation or merging into some third column. is that possible? thanks
1) I started with this sample data.
2) I created a matrix and configured it as shown in the image below.
3) I clicked the forked arrows to show all levels.
4) In the Rows section of the formatting pane, I turned off "Stepped layout".
5) In the Subtotals section, I turned off "Row subtotals".
I don't know if this is exactly what you are looking for, but I think it is the closest I can come up with since you don't want to concatenate the columns together.
If they are from the same table then just drag and drop them into the columns.
The way a matrix works from my understanding in PowerBI is;
Rows are just the headings/categories of the values.
You might need to also go into the format tab, values, and make sure show on rows is on.
For example, let's say our value headings are rainy days and sunny days.
Your columns are months.
The rows will be the 2 categories.
The values will be the values.
As concatenation and "&" does not work in Power BI directquery you can use the below one:
[New_column_name] = if((table_name[column_name]="A" && table_name[column_name]="B"),"AB","NA")
Thanks,
Sachin Kashyap