Grouping by column and concatenating another column - powerbi

I'm trying to group table by the id column and then display the values of another column in a concatenated list. This is the original table:
Original Table
And this is the desired outcome:
Desired Outcome
Is there any way to do this in Power Bi?

You can create a calculated Table using this:
Table2 = SUMMARIZE (
'Table',
'Table'[Column1],
"All", CONCATENATEX ( VALUES ( 'Table'[Column2] ), 'Table'[Column2], "," )
)

Related

Power BI - Comparing data at Row Level and concatenating the respective data in other column for same records

I want to show the consolidated data for similar record in separate column in power bi data.
I have a data with two columns and i want the result like below in third & fourth column
3rd column result nothing but comparing unique id in rows, e.g. 1=2 =false, 2=2=true
4th column result nothing but concatenation of Value column for unique record
could you please help to achieve this in power bi - i want to create custom columns for these two result in data table
We can use CalculatedColumn in DAX:
Result =
CALCULATE(
CONCATENATEX (
CALCULATETABLE ( VALUES('Unique'[Value] ) ),
'Unique'[Value],
", ",
'Unique'[Value],
ASC
), ALL('Unique'[Value])
)
And you Validation may be a measure:
Valid = if(SELECTEDVALUE('Unique'[Value]) = CALCULATE( max('Unique'[Value]), ALL('Unique'[Value])), FALSE(), TRUE())

IFERROR then NA in Power BI

I have two tables are data and report.
The data table contains two columns: item and text. The item and text columns contain duplicates.
I am applying the following calculated column in the report table
RESULT =
CALCULATE (
FIRSTNONBLANK ( DATA[TEXT], TRUE () ),
FILTER ( DATA, DATA[ITEM] = REPORT[ITEM] )
)
In order to get the data from the data table into the report table.
If the item is not available in the data table, then return “NA” according to the item in the report table. My calculated column is showing blanks if the item is not available in the data table but I want "NA" instead of blanks.
My calculated column is picking the min qty according to the item in the report table based on the data table where the same item contains multiple qty but I want max qty in the report table according to the item where the same item contains multiple qty.
Can you please advise?
Herewith attached the power bi for your reference.
https://www.dropbox.com/s/e3fa45f8qz8a2tm/LOOKUP%20MULTIPLE%20VALUE_QTY.pbix?dl=0
Data & Report:
You can get the max with just
RESULT = CALCULATE ( MAX ( DATA[TEXT] ) )
Replacing blanks with NA is possible but it means the RESULT column must be converted to a text data type (since a column cannot have multiple data types).
I don't advise doing that, but you can like this:
RESULT =
VAR MaxText = CALCULATE ( MAX ( DATA[TEXT] ) )
RETURN
IF ( ISBLANK ( MaxText ), "NA", FORMAT ( MaxText, "0" ) )

Count unique matching items as a calculated column

I have two tables are Data and Report.
Data Table:
In Data table contain two columns are Item and status.
The item column contains duplicated entry and the item column contains text and number or number only or text only.
The status column contains two different text/comments, "Okay" and "Not Okay"
The report table
In the Report table, I updated both comments/text as "Okay" or "Not Okay".
I would like to create a new calculated column in the report table in order to get the unique count according to the comments based on the data table columns item and status.
In Excel, I am applying the following formula
F2=SUM((FREQUENCY(MATCH(A$2:$A$19&"",$A$1:$A$19&"",0)*($B$2:$B$19=$D3),ROW($A$2:$A$19))>0)+0)-1
in order to get my final result.
I don't want measure solutions.
DATA TABLE:
REPORT TABLE:
EXCEL LOGIC:
This is much easier in DAX than in Excel and there are many ways to do it.
Here are some possibilities with different approaches:
Desired Result =
VAR Comment = REPORT[COMMENTS]
RETURN
CALCULATE (
DISTINCTCOUNT ( DATA[ITEM] ),
DATA[STATUS] = Comment
)
Desired Result =
COUNTROWS (
SUMMARIZE (
FILTER ( DATA, DATA[STATUS] = REPORT[COMMENTS] ),
DATA[ITEM]
)
)
Desired Result =
SUMX (
DISTINCT ( DATA[ITEM] ),
IF ( CALCULATE ( SELECTEDVALUE ( DATA[STATUS] ) ) = REPORT[COMMENTS], 1, 0 )
)

DAX split a column string into a list and search split values in another table

I have DAX measure which gives list of all selected values in a slicer seperated by comma
Measure =CONCATENATEX(VALUES ( Table[value] ) , [value] , ",")
Measure values are like : ABC,CDEF,EFG
Now there is a table2 which contains following data:
Table2:
Col1 Col2
200 ABC,GHJ,NKUL
300 BPO,CDEF, MNO
500 A
Now I have to create a DAX measure to count rows in Table2 which contains any of split values.
Here row1 and row2 satisfies condition as they contains ABC and CDEF respectively.
Tried with generate list solution but didn't work properly with string.
You should be able to just count rows that contain a comma:
CountSplits =
COUNTROWS ( FILTER ( Table2, CONTAINSSTRING ( Table2[Col2], "," ) ) )

dcast / melt / reshape a table which has calculated columns in power BI using DAX

I have a table with 5 columns
Store ID | Year | Sales Group 1 | Sales Group 2 | Sales Group 3
All fields with Sales Group are calculated using DAX. I would like to create a new table which contains Store ID, Year, Sales Group and Sales Value.
So essentially I would have 3 rows of data for each store ID and Year, each containing sales value for a different sales group
I want a DAX query to convert from Table 1 to Table 2
Table 1:
Table 2:
It would probably be better to do this in Power Query M, which has a built in unpivot transform, but you can get there with DAX:
UnpivotedTable =
// GROUPBY gives you unique combinations of the columns referenced
VAR StoreYears =
GROUPBY (
'Table',
'Table'[Store ID],
'Table'[Year]
)
RETURN
// UNION does what it says on the label, unions multiple tables
UNION (
// ADDCOLUMNS is also self-descriptive - takes a table, adds columns to it
ADDCOLUMNS (
StoreYears,
// After the table arg, ADDCOLUMNS takes pairs of quoted column name and
// DAX expression to evaluate for the value in that column. We create
// two columns, the group and the sum of the source column for that group.
"Sales Group", 1,
"Sales Value", CALCULATE ( SUM ( 'Table'[Sales Group 1] ) )
),
// repeat the pattern above per group
ADDCOLUMNS (
StoreYears,
"Sales Group", 2,
"Sales Value", CALCULATE ( SUM ( 'Table'[Sales Group 2] ) )
),
ADDCOLUMNS (
StoreYears,
"Sales Group", 3,
"Sales Value", CALCULATE ( SUM ( 'Table'[Sales Group 3] ) )
)
)
Best way to do this is in the Query Editor (Performance). Load your data, go to query editor and select the table.
Select the 3 columns of the sales group, go to Transform -> unpivot
Rename the column headers
End result: