DAX Distinct Strings looking in column of Lists - powerbi

I'm trying to do a DISTINCT function with DAX, however looking within list values and not just the column value. Sample data (sorry for the formatting):
Name Word List
Bob {aye, bee, cee}
Bob {aye, bee, cee}
Jim {dee, eee, eff}
Jim {dee, eee, eff}
Ray {aye, bee, cee}
Ray {dee, eeee, eff}
Desired Measure Output
Distinct Words for Jim: 3
Distinct Words for Bob: 3
Distinct Words for Ray: 6
Is there a way for the measure to look through the list and count distinct values?

This doesn't really answer your question how to count distinct in columns of lists but is a workaround to get the desired results.
I would use the query editor and Split Column > by delimiter (under the Home tab) and Replace Values (under the transform tab) to get your table to look something like this:
Name 1 2 3
Bob aye bee cee
Bob aye bee cee
Jim dee eee eff
Jim dee eee eff
Ray aye bee cee
Ray dee eeee eff
After that I would select all columns except Name and use Unpivot Columns, which would make your table look like this (after removing the Attribute column).
Name Word
Bob aye
Bob bee
Bob cee
Bob aye
Bob bee
Bob cee
Jim dee
Jim eee
Jim eff
Jim dee
Jim eee
Jim eff
Ray aye
Ray bee
Ray cee
Ray dee
Ray eeee
Ray eff
By simply dragging the Name and Word columns into a Matrix visual now you would get distinct count.
If you have a lot of data you could instead Group By on name with Count Distinct Rows as Operation already in the Query Editor and you would get a table that looks like your desired result.

Related

Calculating running count and percentages from long-type data

Hello lovely people of SO,
I have a dataset that looks like so:
ID_SALE
PRODUCT
STORE
SE_056
AAA
NORTH
XT-558
AAA
NORTH
8547Y
AAA
NORTH
TY856
BBB
NORTH
D-895
BBB
SOUTH
ER5H
CCC
SOUTH
5F6F-GD
CCC
SOUTH
65-FFD
TTT
SOUTH
56-YU
UUU
SOUTH
I want to be able to plot a table that will show the count of each PRODUCT and the contribution of the global percentage of each PRODUCT as well as the cumulative percentage like so:
PRODUCT
Subtotal
Percentage
running %
AAA
3
0,33333333
0,33333333
BBB
2
0,22222222
0,55555556
CCC
2
0,22222222
0,77777778
TTT
1
0,11111111
0,88888889
UUU
1
0,11111111
1
I also want to be able to have a filter in the PBI sheet that will filter by STORE so if I choose "NORTH" my table will show the following:
PRODUCT
Subtotal
Percentage
running %
AAA
3
0,75
0,75
BBB
1
0,25
1
First THANKS A LOT guys pbi is truly coming for me and my mental health and although I have used the quick-measure feature to get the cumulative total I get get it to sort in order my data and so I figured that DAX is the only way.
if you guys can help me out I will be so thankful I will be very attentive to your responses.
Assuming your table is named "Table".
Subtotal = COUNTROWS('Table')
Percentage = [Subtotal]/CALCULATE(COUNTROWS('Table'),REMOVEFILTERS())
running % =
VAR cursor = MAX('Table'[PRODUCT])
RETURN
CALCULATE( [Percentage], REMOVEFILTERS(),'Table'[PRODUCT]<= cursor)

Group by similar strings in SAS within a column

I have the following table:
Name
----
John Smith
John Smth
Jane Lee
Jane Line
Timothy Brown
Timmothy Brown
Agnes James
Aaron James
Using SAS, how can I group these strings on a large scale to identify those that are similar, so that I can get this table:
Name
----
John Smith
John Smth
Timothy Brown
Timmothy Brown
There are many ways in SAS to perform comparisons of strings. A simple example is using SOUNDEX to find two strings that sound alike.
data have;
input Name $char20.;
datalines;
John Smith
John Smth
Jane Lee
Jane Line
Timothy Brown
Timmothy Brown
Agnes James
Aaron James
;
proc sql;
create table want as
select
A.name
, B.name as name2
, soundex(A.name) as sxname
, soundex(B.name) as sxname2
from have a
cross join
have b
where a.name lt b.name
having sxname = sxname2
;
Other techniques would use a matching criterion based on a metric such as Levenshtein edit distance, which can be computed with COMPLEV. You can also learn more about SPEDIS.
Searching up How to perform a fuzzy match using SAS functions and you will get plenty to chew on. Keep an eye out for papers by Charles Patridge

How do I group my certain rows into a new heading in power BI?

I have a matrix visual with a list of KPI's taken from different tables
Sample Matrix Data visual - ABCDEF are KPIS
Australia NZ India Korea China
A
B
C
D
E
F
I have to add another column to the left of the A,B,C etc called as "Pillar" which will be grouping these existing kpis into further bigger groups
Expected Output :
Australia NZ India Korea China
Dog A
Cat B
Cat C
Bird D
Bird E
Bird F
Bird G
I have to create this new column Pillar and put in my matrix visual.
Challenges I am facing are:
I do not have the list of KPI's in one Table, so do I add this new column in all my tables by going into data transformation?
How do I achieve this?

Row with duplicate values in one column and different values in a second column

In Power BI, I need to identify all distinct duplicate values in a Column A that have distinct values in Column B.
Example input:
Name Index
-------------
john 1
mary 1
john 1
jim 1
john 2
mary 1
jim 2
jim 1
john 2
mary 2
Desired result:
Name Index
-------------
john 1
mary 1
jim 1
john 2
jim 2
mary 2
Column Name in my Power BI is a concatenated column
Is this possible?
You should be able to do this pretty easily in the Power Query Editor GUI.
Select the combination of columns that you want to remove duplicates on (name and index in your case) and then under the Home tab you can select Remove Rows > Remove Duplicates.
This will automatically generate the Table.Distinct M code that chillin suggests.
Provided your previous step is a table, you should just be able to use:
Table.Distinct(nameOfPreviousStep, {"Name", "Index"})
Below is an example of what I mean:
let
someTable = Table.FromRows({{"john",1},{"mary",1},{"john",1},{"jim",1},{"john",2},{"mary",1},{"jim",2},{"jim",1},{"john",2},{"mary",2}}, type table[Name=text, Index=Int64.Type]),
removeDuplicates = Table.Distinct(someTable, {"Name", "Index"})
in
removeDuplicates
Try it out and see if it gives you your expected output (I think it does based on what I've seen).

Sitecore query syntax: Select all female descendents whose parent isn't called Jack

Given a Sitecore content tree of Males and Females (each sex with own template) representing a family tree, how would I select all Female descendents of an item where the parent wasn't called Jack using Sitecore query?
Context: My context item is one of Bob's children. My query shouldn't return Bob himself. Bob also has hundreds of brothers with thousands of descendants that I really don't want appearing in my results.
Bob
Sarah
Jim
Julie
John
Sue
Jack
Anne
Jack
Claire
Mary
The query should return: Sarah, Julie, Sue and Mary but not Anne or Claire.
I can select all female descendents of Bob with:
..//*[##templateid='{insert female template id here}']
But how do I add the parent name != Jack clause?
If you had a "family root" node that did not represent a person by itself, you could do this:
/path/to/family root//*[##name != 'Jack']/*[##templateid = '{template id}']
In your case, you want only a certain person's descendants to be returned. The person themselves should not be included in the result set. In that case, the approach from your comment is the way to go:
..//*[../##name != 'Jack' AND ##templateid = '{template id}']
The results of both queries will include Mary since her direct parent is not called Jack.