Power BI counting names separated by a Semicolon - powerbi

I imported a csv table to Power BI with the following format.
company
products
discounts
1
A; B
X
2
B; C; D
Y
3
C; A; B ; E
X
4
F
Y
Then, I would like to plot a chart / create a table to count the number of companies with discounts on each products.
Products
counts for not discounts (X)
counts with discounts (Y)
A
2
0
B
2
1
C
1
1
D
0
1
E
1
0
F
0
1
Given the products names are separated by ; in the original cell, how can I count those product names separately in Power BI? Many thanks.

Ideally I think you should split the values in the table into its own row. Go to Transform data > Transform > Split by Delimiter. You then can choose the ";" as the delimiter. The PowerQuery of the step would look something like:
= Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Products.1", type text}, {"Products.2", type text}})
Then you can do Unpivot column to flip these 2 columns into rows. Still in Transform tab, you can locate Unpivot. Keep the company and discount columns and unpivot the products ones. PowerQuery should be like:
= Table.UnpivotOtherColumns(#"Changed Type", {"company", "discount"}, "Attribute", "Value")
The remaining steps to bring this onto the table you want should be straightforward I think. Hope this helps

Related

How to create dynamic ranking excluding one column the table in Power BI?

I have a summary table as input to Power BI, sample shown below:
Col1
Col2
Col3
Profit
A
P
E
546
A
Q
F
456
A
P
F
343
A
Q
E
897
I have created a report in Power BI using dynamic ranking. I have used following expression for rank measure:
Rank = RANKX(ALLSELECTED(Table), Calculate(sum(Table[Profit])), ,DESC, Dense)
But when filters are applied, above rank is re-generated using all the 3 categorical columns into consideration. But I would like to re-generate ranking based on only 2 columns (suppose col1 and col2 only) when filters are applied and col3 column is only used for filtering purpose. How can I achieve it?

PowerBI - calculated field to check for dissimilar items in a semi-colon separated list in a row cell

I am using PowerBI desktop to create visualization from data source (a table in excel sheet) and I need to create a calculated field from one of the columns from the data. One of the columns in my data table is as follows:
Technology
A
A;A
B;B;B
C;D;C
A;A;B
B;B;B
D;D
A;
;
;;
I want to create a new column of type Boolean that outputs 1 when only one unique item is in a row of column and 0 when items in the semi-colon separated list are not unique. Like this:
Technology
New Column
A
1
A;A
1
B;B;B
1
C;D;C
0
A;A;B
0
B;D;B
0
D;D
1
A;
1
;
0
;;
0
How can I do this in PowerBI desktop?
EDIT: Updated requirements to test three more cases. (last three rows)
Add a new column and type in the following:
if List.Count( List.RemoveItems( List.Distinct( Text.Split([Technology],";")), {""})) = 1 then 1 else 0

Sum product costs with same ID in Power Query

I have multiple rows with same ID but different products/prices. I would like to get this in Power Query (PowerBI) due to the automation.
Excel formula looks like this:
=SUMPRODUCT(IF($A$2:$A$7=A2;$B$2:$B$7))
And the table is:
A (ID)
B (price)
1
10
1
20
1
5
2
3
2
6
2
1
My goal is to get this:
C (Formula-price)
35
35
35
10
10
10
This step represent Column P & Q (Claims List) in this sheet: https://docs.google.com/spreadsheets/d/1J_nl2_Dgam7JDdyzX-urrO2AEXuCzhQkB1nogTLn2eA/edit#gid=0
In powerquery, right click and group on ID. Add a sum of one of the number columns and then below that, choose All rows as the operation.
After grouping use arrows atop the new column to expand the other columns
Sample, without the expansion
let Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Count", each List.Sum([Column2]), type nullable number}, {"data", each _, type table }})
in #"Grouped Rows"
So I am guessing a little bit but I think you would like to add the sum of B(price) grouped by A(id) to every row in your table. And you would like to use Powerquery for that.
First step would be to import the table into powerquery, then I duplicate the query and group it by ID. The third step is to merge these table by ID
Step 1
I took the following example data
Goto Data/From Table/Range and you should get
Step2 Right click on the query above and select Duplicate
I named the result sumTbl , grouped it by ID and with price as the column to sum
PS In the above step you can change to Advanced and add a second aggreagtion level and then expand. No need to merge!
The result looks like
Step 3 Now you merge both tables. I merged them as a new one
The result is
Now you only need to expand the column sumTbl
The result will be

How to dynamically add rows to column in power bi/power query

I'm facing a challenge in power bi where I need to join Table 1 & Table 2 but the catch is Table 2 needs to be pivoted before joining.
Input:
Table 1
Table 2
Expected Output:
How to build the output table when the Table 2 rows will be increasing daily
Your desired result needs a combination of Unpivot, Merge and Pivot steps.
You can follow the following steps:
Convert the Date column to Text type.
Unpivot columns Sales in KG & Sales in Amount from Table 2 - it will create 2 columns called Attribute & Value
Merge columns Date & Attribute to create a new column (lets call it columnHeaders) - this will be in the format - 1/3/22 Sales in KG, 1/3/22 Sales in Amount ...
Merge Table 1 into Table 2 and expand the Product Name column
Now you will have 4 columns - Product Code, columnHeaders, Value, & Product Name
Pivot columnHeader using the Value column for values
You should have your desired result.
I dont know why you try to unpivot your table. Just use a Matrix visualization:
Model relationship:
Imput data + output:
sum of kg = CALCULATE(sum(Table2[Sales in kg]))

Take row wise percentages on power BI tables

I Have the following table on power BI:
For which I have to take the percentages by of each category by class, but when a show the values as percentages of the total on power BI I get the following:
Which is a column wise percentage, how can I get it this way:
If you unpivot those columns, in the query editor so that your data is shaped like this:
Class Attribute Value
A Aproved 10
A Reproved 10
B Aproved 3
B Reproved 2
C Aproved 2
C Reproved 9
D Aproved 3
D Reproved 1
Then it's as simple as putting Class on rows, Attribute on columns and setting the implicit measure for Value to Percent of row total.