power bi: split column values by character and calculate sum - powerbi

I have a table in which numeric values are there, but in some rows may contains values separated by comma. Since comma is in there so the data type of the column will be text.
I want to calculate sum of this column.
Here is my table-
Id Values
A 12
B 13
C 15
D 13,11,12
E 16
I want my sum to be - 12+13+15+13+11+12+16
Since the datatype of this column will be text so can the sum be calculated like I want or I have to do something like this-
Id Values
A 12
B 13
C 15
D 13
D 11
D 12
E 16

You can split the column by delimiter:
And split it into rows instead of columns:
The result will be as what you expected:
Then you can sum it as usual with DAX:
Sum = SUM(Data[Values])

Related

SAS - How to get the column name as a value to another column (based on its value as condition)

Three columns are depicted in the picture - abc, def, and xyz. The next two columns are dervied from these 3 columns. min column calculates the min value out of these 3 columns. mincol column should give the column name which belongs to the min value.
You can
Use the VNAME function to retrieve the variable name of an element in a variable array.
Use the WHICHN function to find the index of the first occurring value in an array
Use the MIN function to find the minimum value in an array
Put them all together, such as:
data have;
input abc def xzy;
length min 8 mincol $32;
datalines;
1 2 3
2 0 3
-1 0 -3
;
data want;
set have;
array values abc def xzy;
min = min(of values(*));
mincol = vname(values(whichn(min,of values(*))));
run;

How to sum value in column and average

Please help me, following below
name | value | month
A 5 mar
B 6 apr
i need sum column value then average
how should i do.
First create a calculated column as below-
calculated_column = column B + column C
Now create the average Measure as below-
avg = AVERAGE(calculated_column)

How can I get the last value of a column in my dataset in power bi?

In the given table how to get the last value of a particular column in a dataset
Roll No Name Index Score
1 ab1 1 23
2 ab2 2 43
3 ab3 3 42
Here we have to pick the Last Row Score value?
1) The first thing we have to create a custom index column in the table
2) Then we have to use the below formula to get the last Row Score value Score value
CALCULATE(LASTNONBLANK(Table[Score], 1), FILTER(ALL(Table), Table[Index] = MAX(Table[Index])))
The result would be 42.

Replace a row value with previous by group in SAS

Is there a way I could replace a row value to its previous row by each group?
Below is the before and after data set. Product for each type - C needs to be changed as type - L for each customer when the ID is same it has the highest amount.
Before
ObsCust LINK_ID Type Product Amount
1 1 12432 L A 23
2 1 12432 C B 0
3 2 23213 L C 234
4 2 23145 L D 25
5 2 23145 C E 0
6 3 21311 L F 34
7 3 21324 L G 45
8 3 21324 L H 35
9 3 21324 C I 0
After
Cust LINK_ID Type Product Amount
1 12432 L A                234
1 12432 C A                   -  
2 23213 L C           23,212
2 23145 L D                335
2 23145 C D                   -  
3 21311 L F                323
3 21324 L G             2,344
3 21324 L H                  34
3 21324 C G                   -  
Thank you!
if i understand correctly, you want to have product value for C Type be the product associated with the highest amount in L Types. If this is correct one possible way is to use the following. First the product with the highest amount for L-Type within each group of customers and IDs are calculated as follows:
note that the original dataset is assumed to be named "example".
proc sql;
create table L_Type as
select cust, LINK_ID, product, amount
from example
where type = 'L' and amount = max(amount)
group by cust, LINK_ID
;
quit;
then product calculated above is coded for c type in the original example.
proc sql;
select
e.cust
, e.LINK_ID
, e.type
, case when e.type = 'C' then b.product end as product
, e.amount
from example e left join L_Type b
on e.cust = b.cust and e.LINK_ID = b.LINK_ID
;
quit;
So you have a couple processing tasks to do:
Have you considered all the edge cases ?
For a customer find the row(s) with the maximum amount.
Is one of them type L ?
No, do nothing
Yes, track the Product and LinkId as follows
Is there more than one 'maximal' row ?
No, track the Product & LinkId from the one row
Yes, Is there more than one Product in the rows ?
No, track the Product value
Is there more than one LinkId ?
No, track the LinkId
Yes, Which LinkIds?
Track all the different LinkIds
Track one of these: first, lowest, highest, last LinkId
Yes, now what ?
Log an error ?
Track one of the Product values because only one can be used, which one ?
first occurring ?
lowest value ?
highest value ?
last occurring ?
For the tracked LinkIds (there might not be any) apply the tracked Product to the rows that are type C (or perhaps type not L)

Column combine two datasets of different size

I have two datasets of the following structure
ID1 Cat1
1 a
2 a
3 b
5 b
5 b
6 c
7 d
and
ID2 Cat2
11 z
12 z
13 z
14 y
15 x
I want to column-combine then and then have the unmatched rows just be missing. So ultimately I want:
ID1 Cat1 ID2 Cat2
1 a 11 z
2 a 12 z
3 b 13 z
4 b 14 y
5 b 15 x
6 c
7 d
The purpose of this is that I have two sorted datasets (by ID) and want to do a matching of the first category (Cat1) with the second (Cat2). The second category has a predefined number of "slots" and those slots should be matched on the order of the IDs. The only relationship between ID1 and ID2 is that they are ordered the same way. So the two lowest should be a match and so on.
You want a one to one merge.
The documentation is here
In order to do a one to one merge you just need to merge without a by statement
This type of merge simply matches the observations based on its row number, so be careful, it may give you unintended results if you are missing a row you thought you had or something else wasn't as you expected.
for example:
proc sort data = have1; run;
proc sort data = have2; run;
data want;
merge have1 have2;
run;