DAX code that only shows measure dependant on specific filtered dimensoins - dax

I have a table which in alle general is like below
enter image description here
enter image description here
In my report I only want to allow the measure "Population" to be visible for the dimension Classtype when Classtype is chosen in combination with School.
I am trying to define this in DAX.
E.g. the rule is:
If School and Classtype is chosen then show population. This works with: if (isinscope [Classtype] && ISINSCOPE ([School], population...
OR if any other dimension NOT IN COMBINATION with classtype is chosen then also show population.
Else blank
Can anyon find out how to write the 2nd par?

Related

Sort Order - Sort by Dimension not Boolean

I am calculating the percent of total for different error categories. I am creating separate bar charts for each of the different categories and would like to have the error categories in the same position on each bar chart.
The order that I would like to set is: Demographics, Specialty and Board Certifications, Service Name and Location, Remit Location, General
However, Tableau appears to be sorting by the Boolean operator (True/False) first then on the Error Category dimension.
Is there a way to sort by the Error Category without taking into account the Boolean?
I have attached an example of what I am trying to achieve.
enter image description here

RASA: Intent ranking without normalisation

I want create model with config for which resultat as like below. I mean the ranking of intentions that do not add up to 100%, but each individual intention takes a value in the range of 0-100%.
I need an example configuration in RASA, for which I will not get a ranking of intentions whose values ​​will add up to 100%.
enter image description here

Setting parameter controls and using filters

I currently have a dataset of speeding fines in NSW.
I've created a bar chart that displays the top 10 frequencies of speeding offenses. These offenses are split up between school zone offenses and normal speeding offenses.
I'm trying to set a parameter control where the end-user can toggle showing the top 10 normal speeding offenses (pink), top 10 school zone offenses (purple) or both together (pink and purple).
I've gotten the below parameter control:
However nothing happens to the bar-chart.
My Dataset looks like the following:
I have a School Zone Indicator boolean that is a Y if the speeding offense occurred during school zone time.
Can someone help me figure out in filtering this out when setting parameter controls?
The answer is based on this article showing how to add all to a parameter in Tableau.
We need to create a parameter with the same values as the field. As your field is either Y or Null let's create a new field to convert the Null to N. Call it isSchool with the formula:
IFNULL([SCHOOL_ZONE_IND],"N")
Create a parameter based on that field with the values Y, N and All. Display As whatever you want, so you can display parameter value All as Show Both if you wish.
Put [isSchool] to filters.
In the filter you want to filter Condition - by Formula. Enter this formula:
IFNULL([isSchool],"1")=IF [YourParam]!="All" THEN [YourParam] ELSE IFNULL([isSchool],"1") END
That should do it.

Highlighting with slicer Power BI

I have a Dashboard with different visuals.
Data is made up of different values for insurance companies.
I want my slicers/filters to not filter all data, but to only highlight the chosen company.
For example, in my slicer I choose the insurance ABN.
Instead of showing me the value for ABN only in my visuals, I want all other values to still be visible and ABN's value to be highlighted in the visuals.
Does anyone know how to do this?
You can use conditional formatting to achieve this. Lets say that we will change the background color to "highlight" a row (or cells, to be precise).
First, we need a slicer, which will not filter our data. We can do this by duplicating our source table, removing the unnecessary columns and making sure there is no relationship between the source and the duplicate. So if we have a source table, named Table, like this:
Right click on it and select Duplicate:
Then right click the title of the column you want to keep and select Remove Other Columns to get a list of company names only (you may also remove the duplicates, but it's not required). Then in the model delete the relation between both tables:
Now you can place a table showing company name and sales from your data source, and a slicer for company name from the duplicate table. At this point selecting values in the slicer should not affect the table.
Now you need to capture the value of the slicer and use it in a measure, which will determine should current row be highlighted or not. You can use SELECTEDVALUE for that, but note that it will give you a value only if there is a one selected in the slicer. If you want to support highlighting of more than one company, it gets a bit more complicated.
Make a new measure in your source table, like this:
Measure = IF(HASONEVALUE('Table (2)'[Company name]);
IF(SELECTEDVALUE('Table (2)'[Company name]) = MAX('Table'[Company name]); 1; 0);
IF(ISFILTERED('Table (2)'[Company name]) && COUNTROWS(FILTER('Table (2)'; 'Table (2)'[Company name] = MAX('Table'[Company name]))); 1; 0))
In case there is only one value selected in the slicer (see HASONEVALUE), then our measure will return 1 (highlight) or 0 (don't), comparing it with the current row.
Otherwise (i.e. there is no selection in the slicer, or there are 2 or more companies selected), then we will look at the filtered list of companies (Table (2)) - if it contains current row, then 1 (highlight), otherwise 0 (don't). But we will also handle the case, where there is no value selected in the slicer. In this case the list will contain all the companies, i.e. all rows will be highlighted. Here comes ISFILTERED. And at the end, if the list is filtered and current row exists in the filtered list, then 1 (highlight), otherwise 0 (don't).
Now, you need to use this measure to change the background of the column - right click each column in your table and select Conditional formatting -> Background color:
Then format by rules, where Measure >= 1 like this:
Now, when there is no selection in the slicer, there are no rows highlighted in the table:
If you select one company, it is highlighted:
It also work if there are multiple companies selected:
Thank you Andrey for your step-by-step explanation which as been incredible helpful. I'd like to follow up with a further question, particularly regarding the comment below.
"You can use SELECTEDVALUE for that, but note that it will give you a
value only if there is a one selected in the slicer. If you want to
support highlighting of more than one company, it gets a bit more
complicated."
In my model, I've linked a third table (Table (3)) to Table (2) with a many to one relationship with Table (2). Therefore when I click on Table (3), it will filter Table (2), which acts as a slicer for Table (1).
When only 1 value is filtered in Table (2), it conditionally formats the cells in Table (1). However, when more than 1 value is filtered in Table (2), conditional formatting fails.
As I'm looking to avoid manually selecting multiple values in the slicer (Table (2)), I was wondering if there's a workaround for SELECTEDVALUE such that it is able to conditionally format when I filter more than 1 value in Table (2).

Column slicer in Power BI report?

I have a requirement to cook my report with local languages. I have three description columns in my table and need to show one at a time based on user input.
Example:
CustName | Product | English_Description | Swedish_Description
My table has 5 millions of records, so i can't go for un-pivot the description columns. if I do un-pivot, my table becomes 10 millions of records. it's not a feasible one.
Some sample data would be useful. However, you could do a disconnected (or parameter) table for the language selection:
Language
--------
English
Swedish
This table wouldn't be related to anything else, but you could then use measures for your product descriptions such as:
Multi-lingual Description =
IF (
'Disconnected Table'[Language] = "Swedish",
MAX ( [Swedish_Description] ),
MAX ( [English_Description] )
)
With this logic, if no language is picked, the English description will be used. You could use different behavior too (for example use HASONEVALUE to ensure a single value is selected, and display an error message if not).
MAX in the measure is because a measure has to aggregate; however, as long as your table has one product for each row, then the MAX of the product name will be the product name you expect. Having more than one product per row doesn't make sense, so this should be an acceptable limitation. Again, to make your measure more robust, you could build in logic using HASONEVALUE to show BLANK() or an error message if there is more than one product (e.g. for subtotals).
More information:
HASONEVALUE: https://msdn.microsoft.com/en-us/library/gg492190.aspx
Disconnected Tables: http://www.daxpatterns.com/parameter-table/

Resources