Power BI pivot column with no aggregation errors - powerbi

I have a simple table that I want to pivot by the 'COLUMN_NAME' column:
When I pivot and aggregate by count it works fine:
When I try to pivot without aggregation, it gives this error:
Expression.Error: There were too many elements in the enumeration to
complete the operation. Details:
[List]
Here is what I expected to happen:
thx in adavnce

You need to pivot against a specific column, otherwise the powerbi engine can't determine how to keep the data in rows consistently.
Your input needs to be in a format similar to this:
RecordID
COLUMN_NAME
COLUMN_VALUE
1
PRODUCT_SUB_FAMILY
MYPRODUCT
1
MFG_STEP_NAME
FT1
1
QTY_IN
678
1
QTY_OUT
480
1
AGG_YIELD
0.70796
2
PRODUCT_SUB_FAMILY
MYPRODUCT
2
MFG_STEP_NAME
SLT1
2
QTY_IN
66
2
QTY_OUT
0
2
AGG_YIELD
0
And then when you pivot, you select the RecordID as the column you pivot against.

Related

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

Use DAX to get data between 2 tables

I have table 'tblA' with only 1 column named 'Value'
Value
1
2
The second table 'tblB' with several columns
Col1 Col2
Test A
Dump B
How can I have a join between them so that I will have new table with result like this (each value in tblA will fill in to all rows in tblB):
Col1 Col2 Value
Test A 1
Dump B 1
Test A 2
Dump B 2
I also tried to use for loop to get one-by-one value in tblA. But it seems that DAX didn't support loop.
Please advise.
Use expression for a calculated table
tblC = CROSSJOIN ( tblA, tblB )

Informatica : Count the number of rows based on sequence of number

I have table where source has 1 column, like below. for example, column name is A and I have set of records in the source.
A
1
1
1
2
2
3
I want to populate two columns in target, Say columns are A and B.
Column A in the Target has same values as in source and column B has count
A B
1 1
1 2
1 3
2 1
2 2
3 1
Can someone please explain how can i achieve this.
Thanks in advance
If source is a dbms like oracle, you can use source qualifier overwrite sql like below. Use row number and partition by to generate sequence for every A.
Select
A, row_number() over(partition by A order by A) as B
From mytable
If you're looking for infomatica only solution then this is how you can do it.
Sort the data by column A
Use ex transformation, create one in/out two var, and one out port.
We are going to compare first val with prev val, if they r same, add 1to the sequence else start from 1 again.
A in/out
v_B = iif (A=prev_A, v_B +1, 1)
prev_A=A
o_B =v_B
Link A and o_B to the target.

How can I create a total that is filtered by selection and slicer?

Problem
I would like to create a multi-layer histogram that shows the distribution of var1 on the first level and var2 on the second level, with a legend by source, like this:
The value should show the percentage w.r.t. the total of a source, with all the selections and slicers applied. The percentages shown in the histogram should always sum to 100% per source.
Example data
I have the following example data:
source var1 var2 count
A 1 1 100
A 1 2 12
A 1 3 34
A 2 1 1612
A 2 2 23
A 2 3 43
B 1 1 200
B 1 2 320
B 1 3 12
B 2 1 1757
B 2 2 345
B 2 3 32
What have I tried
I can achieve a total per source with the following measure without the filtering part:
percPerSource =
DIVIDE(
SUM(input[count]);
CALCULATE(
SUM(input[count]);
ALLEXCEPT(input;input[source])
)
)*100
If I turn on Drill mode and click on the columns of var1 I get the following, undesired result (the percentages do not sum to 100%):
Another attempt was using the ALLSELECTED function:
percSelected =
DIVIDE(
SUM(input[count]);
CALCULATE(
SUM(input[count]);
ALLSELECTED(input[var1])
)
)*100
This shows only 100% on the var2 level:
I think this will do what you're after:
percPerSource =
DIVIDE(
SUM(input[count]);
CALCULATE(
SUM(input[count]);
FILTER(
ALLSELECTED(input);
input[Source] IN VALUES(input[Source])
)
)
)*100
This takes all the selected values as the universe you are filtering on but only selects the rows that in your local filter context.
The FILTER function takes a table as its first argument and a condition as the second argument. It iterates through every row in the table passed into it and checks if the condition holds and returns a table with only the rows where the condition evaluates to True.
The VALUES function returns a list of distinct values of the column specified evaluated within the local filter context.

mysql connect all fields in two columns

I have a view with two columns: a person's ID (a number) and the sector that they below to (given as numbers 1-5).
I want to create a view to show whether people belong to the same sector. I think this would have three columns: ID1, ID2, and SameSector. The first column would list IDs, and for each ID in column 1 the second column would list ALL of the IDs. The third column would be an if statement, 1 if the sector was the same for both IDs, 0 if it wasn't. This is made slightly more complicated because a person can belong to more than one sector.
For example:
I have:
ID Sector
1 1
2 1
2 5
3 1
I want:
ID1 ID2 SameSector
1 1 1
1 2 1
1 2 0
1 3 0
2 1 1
2 1 0
etc.
I'm guessing this involves some sort of self join and if statement but I can't figure out how to get all of the ID fields to be listed in ID1 column and matched to all of the ID fields in ID2 any ideas?
This should be what you want:
SELECT a.ID AS ID1, b.ID AS ID2, IF(a.Sector=b.Sector,1,0) AS SameSector
FROM theTable AS a, theTable AS b
http://sqlfiddle.com/#!2/f2cbc/4
I initially had a much more complicated query, but then realized you wanted a complete cross-join, including the same ID comparing to itself.