Frequency Counter - powerbi

Good evening everyone, I'm having trouble resolving the following question:
I have "Table 1" containing the occurrence records and "Table 2" containing the occurrences.
I need to set up a VIRTUAL TABLE or VIEW TABLE that presents the occurrences and their frequencies as follows:
Tables with Perspective
The most I could do was bring the occurrences with the total number of rows in the table, ie the same amount X for all.
Last try using DaxStudio

You need to create a measure to show the numbers in the report.
But first, it is recommended to transform the table into a form like below, where each occurrence appears in each row. This has a lot of advantage to make the DAX measure simpler, more accurate, and run faster.
This can be easily achieved using Power Query Editor. The required steps are,
Select the comma delimited occurrences column.
In Transform tab, click Split Column and choose By Delimiter.
Make sure Comma and split at Each occurrence of the delimiter is selected by default.
In Advanced options, select split into Rows, then click OK.
Then you can define a measure to count the number of occurrences, which is as simple as below.
Count = COUNTROWS ( Tabela1 )
Now, in the report area, you can use the measure to obtain the desired output.

I have recreated your tables and here is the DAX for Table3 (perspectiva):
Table3 =
VAR uniqueOccurences = DISTINCT(Table2[Occurence])
RETURN
ADDCOLUMNS(uniqueOccurences,
"count",
VAR currentOccurence = [Occurence]
RETURN
CALCULATE(COUNTA(Tabel1[ID]),
FILTER(Tabel1, CONTAINSSTRING(Tabel1[Occurences], currentOccurence) = TRUE()))
)
This returns the following table:
Please mark this as the solution if this answered your question :)

Related

Power BI LOOKUPVALUE with a column of values for the search items? (VLOOKUP alternative)

In Power BI, I need to create a VLOOKUP alternative. From the research I've done, this is done with the LOOKUPVALUE function, but the problem is that function needs one specific SEARCH ITEM, which isn't super helpful in a VLOOKUP type scenario where you have a full column of values to search for?
Given these two tables, connected through the user_name and first_name columns:
...what's the formula needed in order to create a new column in the Employee_Table called phone_call_group by using the names as the search items in order to return the group they belong to? So how can I end up with this?
(Forget that the entries in each table are already sorted, needs to be dynamic). Will be back tomorrow to review solutions.
In Power BI you have relations between tables instead of Excel's VLOOKUP function.
In your case you just have to create a one-to-one relation between
'Phone_Call_Table'[user_name] and 'Employee_Table'['first_name]'
With that you can add a Calculated Column to your 'Employee_Table' using the following expression:
phone_call_group = RELATED(Phone_Call_Table[group])
and in the data view the table will look like this:
LOOKUPVALUE() is just a workaround if for other reasons you can't establish that relation. What you've been missing so far is that in a Calculated Column there is a Row Context which gives you exactly one value per row for the <search_value> (this is different from Measures):
alt_phone_call_group =
LOOKUPVALUE(
Phone_Call_Table[group],
Phone_Call_Table[user_name],
Employee_Table[first_name]
)

How to hide blanks in a matrix visualization with hierarchical rows

I've built a table of data following this helpful guide:
https://www.daxpatterns.com/parent-child-hierarchies/
I'm following it exactly but I'll still explain things here so you don't have to go through the whole article if you don't want to. I have a table of Names with corresponding keys, and ParentKeys forming hierarchies.
I added a column for the path, columns for each level of the path, depth of hierarchy and an IsLeaf column:
If I want to make a matrix and include City (from another table), all hierarchies will expand to the maximum length, and blanks are filled in with the "parent's" name:
The DAX Patterns website explains how to get around this. First add these two measures:
BrowseDepth = ISFILTERED (Nodes[Level1]) + ISFILTERED (Nodes[Level2]) + ISFILTERED (Nodes[Level3])
MaxNodeDepth = MAX (Nodes[HierarchyDepth])
And then you can factor that into calculations with this measure:
Sales Amount Simple =
IF (
Nodes[BrowseDepth] > Nodes[MaxNodeDepth],
BLANK (),
SUM (Transactions[Amount])
)
If this is the only value on a matrix visual, it turns out fine:
But if I add any other values, I get expanded hierarchies and blanks again:
My problem would be solved if I could filter out blank values, but that filters out the entire hierarchy. Do I have to make a measure using the Sales Amount format above for every value I want to include? I'm trying to add things like addresses that can't be aggregated.
Basiacally yes, you have to re do the measure. However you can embed existing into this patern which makes it a little easier.

Refer to slicer-filtered table in DAX calculated column

I'm beginning to think that what I'm looking for isn't actually possible.
I have two datasets - one of Titles and one of Keywords. Only one column from each is relevant to this query - Titles[Title] and Keywords[Keyword]. So pretty straightforward data. Titles has around 2 million rows, and Keywords will eventually have ~500-1000.
I would like to display a slicer of Keywords[Keyword] values, which will filter the Titles dataset where Titles[Title] contains one of the selected Keywords[Keyword] values.
I tried creating a DAX calculated column on Titles like below -
Matches = IF(SUMX(FILTER('Keywords','Keywords'[Keyword] <> ""),FIND(UPPER('Keywords'[Keyword]), UPPER(Titles[Title]),,0)) > 0,1, 0)
I then apply a report level filter for Matches >= 1. This works for all keyword values, but is not aware of the selection in the slicer.
I tried changing it to use ALLSELECTED('Keywords'[Keyword]) as the first argument passted to FILTER, but this doesn't seem to have any effect.
As a test, I created a Calculated Column and a Measure with the exact same DAX -
CONCATENATEX(VALUES(Keywords[Keyword]), Keywords[Keyword], ",")
This displays the slicer selection delimited by commas for the measure, but not for the column. Since I want to calculate this per row and filter the report based on this, a measure isn't suitable.
Is there any other way I can refer to the filtered Keywords[Keyword] in my calculated column? Or is there a way that a Measure could actually be used to achieve this? Or is there a completely different approach that I could try?

Parsing DAX Query with Regular expression to get measures and dimensions

I want to create an application that uses Extended Events to analyze the usage of Azure Analysis Services models.
Specifically, I want to know what measures and dimensions the end users are using.
I look at the QueryEnd event and try to parse the TextData field. Depending on the tool used for querying the model I get either MDX or DAX in the TextData.
I think I have managed to parse the MDX with this RegEx: ([[\w ]+].[[\w ]+](?:.(?:Members|[Q\d]))?)
(from this post: Regular expression for extracting element from MDX Query)
Now parsing the DAX is the problem. If I query the model from fx PowerBI I get a DAX like this:
EVALUATE
TOPN(
502,
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL('Product'[Color], \"IsGrandTotalRowTotal\"),
\"Order_Count\", 'SalesOrderDetail'[Order Count]
),
[IsGrandTotalRowTotal],
0,
[Order_Count],
0,
'Product'[Color],
1
)
ORDER BY
[IsGrandTotalRowTotal] DESC, [Order_Count] DESC, 'Product'[Color]
What I would like to match with the RegEx is:
'Product'[Color] and 'SalesOrderDetail'[Order Count]
And.... how would i know that Order Count is used as a measyre while Color is an attribute of the Product dimension?..... guess I won't?
Thanx a lot
Nicolaj
think I just found a possible solution for parsing both DAX and MDX queries:
([\[\'][\w ]+[\]\']\.?[\[\'][\w ]+[\]\'])(?!.*\1)
This will give me what I need.... without duplicates. Improvements are welcomed :-)
For disambiguating columns from measures, I would query the DMVs for the deployed model to get a list of columns and a list of measures. Then you can just look up your parsed tokens in the two lists:
DMV docs
Column DMV
Measure DMV.
Note that measure names are globally unique among the population of column and measure names, so that is an easy lookup (just throw away the table reference). Column names are only unique within the table they belong to.
It looks like you've already got a regex that's working for you, so run with that.
I'll also note that almost all PBI visuals which are returning anything other than a simple list (e.g. slicers or one column tables will return just a list) will follow the pattern of the query you shared.
Measures should all be in later args to SUMMARIZECOLUMNS. The pattern is:
SUMMARIZECOLUMNS (
<grouping columns, optionally in a ROLLUPADDISSUBTOTAL>,
<filters, defined above in VARs>,
<measures as ("Alias", [Measure]) pairs>
)

power BI diaplay one value

I am using Power BI to bring together data from several systems and display a dash board with data from all of the systems.
The dashboard has a couple of filters which are then used to display the data relating to one object across all systems.
When the dashboard is first loaded and none of the filter have been selected, the data cards display information from all rows in the table.
Is there a way to make a data card only display one row of data?
or
Be blank if there are more than one row of data?
There's no direct way to look at the number of rows in the visual, count them, and do something different if there's more than 1.
That said, there are a few things you can do.
HASONEFILTER
If you have a specific column in your table that, when selected, filters your results to a single row, then you can check if there's a filter on that column using HASONEFILTER. (If you have multiple alternative columns,any of which filter to a single row, that's ok too.)
You could then create a measure for each column that tests HASONEFILTER. If true, return the MAX of the column. (The reason for MAX is because measures always have to aggregate, but the MAX of a 1-row column will be the same as the value in that column.) If false, return either BLANK() or an empty string, depending on your preference.
E.g.
ColumnAMeasure = IF(HASONEFILTER(Sheet1[Slicer Column]),MAX(Sheet1[COLUMN A]), "")
ColumnBMeasure = IF(HASONEFILTER(Sheet1[Slicer Column]),MAX(Sheet1[COLUMN B]), "")
where Sheet1 is the name of the table and "Slicer Column" is the name of the column being used as a slicer
HASONEVALUE
If you have multiple columns that could be used as filters in combination (meaning that having a filter applied on "Slicer Column" doesn't guarantee only 1 row in the table), then rather than testing HASONEFILTER, you can test HASONEVALUE.
ColumnAMeasure = IF(HASONEVALUE(Sheet1[COLUMN A]),MAX(Sheet1[COLUMN A]), "")
ColumnBMeasure = IF(HASONEVALUE(Sheet1[Column B]),MAX(Sheet1[COLUMN B]), "")
Notice that HASONEVALUE tests the current column you're trying to display, rather than a slicer column like HASONEFILTER.
One side-effect of HASONEVALUE is that, if you're filtered to 3 rows, but all 3 rows have the same value for column A, then column A will display that value. (Whereas with HASONEFILTER, column A would stay blank until you're filtered to one thing.)
Low Tech
Both answers above depend on a measure existing for every column you want to display, so that you can test whether to display a blank row or not. That could become a pain if you have dozens of columns.
A lower-tech alternative is to add in an additional row with blanks for each column and then sort your table so that that row always appears first. (And shorten your visual so only the top row is visible.) Technically the other rows would be underneath and there'd be a scrollbar, but at least the initial display would be blank rather than showing a random row.
Hopefully something here has helped. Other people might have better solutions too. More information:
HASONEFILTER documentation: https://msdn.microsoft.com/en-us/library/gg492135.aspx
HASONEVALUE documentation: https://msdn.microsoft.com/en-us/library/gg492190.aspx