Selected filters by default - Power BI - powerbi

Imagine that I have a column with the following values: [A1,A2,A3,A4,T1,T2,T3]
Now, I have a slicer with the mentioned column, but I need that the the "Ts" (T1,T2 and T3) are always selected / filtered and when I choose a specific "A" (A1) for example, dosn't filter the "T".
For example:
If I select with the slicer "A1" the filter in the page should include: [A1,T1,T2,T3]
If I select "A2": [A2,T1,T2,T3]
So If I select an "A" it have to select the specific "A" and all the "Ts".
How can I do that? With filters? relationships?
Thanks

Short answer: we need a parameter table.
This because we might be able to write a measure that internally sets the filter according to our specification, but the Power BI visual would intercept the slicer setting first and would show only the selected rows or columns (for a matrix visual).
Assuming we have the table
this measure ignores any selection from the slicer, computing the total of the whole column, but the matrix visual will only show the row selected with the slicer
TotalV = SUMX(ALL(T), T[V] )
To solve this we can build a parameter table with the combination we want when selecting the F parameter, for instance like the following Parameter table
The column P is to be used in the slicer, while the column F is used to set up a bi-directional relationship with the original T table
Now we create the relationship
We create the measure
SumV = SUM(T[V])
setting the slicer over 'P' and a matrix with 'T[F]' on the rows and the measure '[SumV]' as value we obtain the desired behavior
Additional considerations:
the Parameter table can be generated manually or using a DAX
calculated table
to build a better model we might create a dimension for F
the bidirectional relationship in this configuration doesn't make
the model ambiguous, but we must pay attention when adding tables
and relationships to the model

Related

Measure inside Calculated Column; but measure depends on slicer selection

I have a tricky situation in Microsoft Power BI, and DAX language:
I am developing a new Calculated Column called Status_CC in a table called Customers; we refer to this formally as - Customers[Status_CC].
This calculated column (Customers[Status_CC]) has a number of conditions in its derivation, I am using SWITCH statement to develop it.
i.e.
Status_CC = SWITCH(
TRUE(),
.........
)
One of the conditions to develop the this Customers[Status_CC] calculated column is: Customers[HireDate] > [BonusDate].
The intersting part is, HireDate is an existing column in the Customers table.
However, [BonusDate] is a measure; this measure is developed using another table called WorkHistory.
A column (called PayCategory) from the WorkHistory table acts as a slicer in the report visual. The PayCategory column determines the value of the [BonusDate] measure.
I am using the DAX function ALLSELECTED on the slicer - the WorkHistory table's PayCategory column, to develop the [BonusDate] measure.
My question is, will the calculated column Customers[Status_CC] work correctly, if it depends on the [BonusDate] measure, which in turn depends on another table WorkHistory, which feeds PayCategory that acts as a slicer ?
I don't see any syntax error in Customers[Status_CC], but not sure whether the numbers are right.
My final report visual in Power BI Report View has:
-several columns from the Customers table, including the calculated column Customers[Status_CC]
-a slicer with PayCategory from the WorkHistory table that dictates the value of the [BonusDate] measure.
Any advice, please?
Measures used in calculated columns are calculated at model refresh time for each row. The row context is transformed to a filter context during the calculation of the measure, and is the only active filter for the measure calculation. So no report filters or slicers would be active at that point.
Note for that non-measure expressions the row context is not transformed to a filter context, so you would see a global total on each row, unless you explicitly use calculate which always changes the row context into a filter context.

Power BI - How to view zeros in the matrix table visual

I'm currently building a report in Power BI. I added a matrix table along with its data. The matrix table just consist of sums per column (shown below).
There are multiple of slicers I have for the report. The problem is when I start filtering, the data disappears from the matrix. Instead of disappearing, I want it those values to be zero.
I have already used the measure: IF(ISBLANK(SUM(COUNT)), 0, SUM(COUNT) And it still did not work (shown below). What should I do so that the zeroes would appear on the matrix table?
There are two things you need for this approach to work
You need your Categories in a separate table to the rest of your data (joined by category ID) - if you don't have an ID, you can get away with Category name). You can build this table in DAX with something like CategoryTable = DISTINCT(MyData[CategoryName]). This new table and your data table need to be linked with a relationship. On your visual, use the Category from the Categories table and the measure you have created.
Make sure "Show items with no data" is checked on the matrix's fields.

How to add calculated column to existing table that would ignore selected value in a slicer Power BI

I need to add calculated column that would ignore values selected in a slicer:
I tried:
all users = ALL(Sheet1[UserName])
But it gives me an error: A table of multiple values was supplied where a single value was expected.
A calculated column cannot be affected by a slicer but that's not what you seem to be referring to.
It appears you are trying to create a visual that lists all the users. For this, you can put Username on a table visual and disable the filtering from the slicer by going to the Format tab and clicking Edit interactions.
If I understand you correctly, You have to use ALL() Function by
creating new table Under the modelling tab

How can I have dynamic axis which is responsive on slicer value, without using bridge table, use just DAX

Hi everyone, I have a chart which I need that the x value (Axis) changes by changing the slicer value (this slicer is the yellow one that has all the Dims (x values)) and it comes from DimList table. For example, at the moment the chart is totalfreight by custid, but I need if I check the empid from the yellow slicer the chart value changed to totalfreight by empid. This happens for all of the slicer values.
But I don't like bridge table or any method that has a bad effect on performance because the FactTable has a billion rows and I modeled it in SSAS, tabular model and has a live connection. Thanks in advance.
I assume you're referring to the approach that uses a bridge table described in this article. I agree that you may face some performance problems given the amount of data in your model.
First of all, you should try to see if there's some other Power BI frontend functionality that you can use directly in the report, without changing your data model. Perhaps you can use Power BI bookmarks, links or maybe a custom visual?
If not, there's another approach you can use in the data model, that does not rely on bridge tables. Disclaimer: I haven't tested this - there could be other performance issues involved.
Construct a new dimension table with all the members from your individual dimensions. Ie. create a union of all EmpIDs, CustIDs, etc. Make sure you indicate the type of ID in a separate column. The table should look like this:
DimensionId MemberId
categoryid 1
categoryid 2
categoryid 3
custid 1
custid 2
custid 3
...
Let's name this table 'All Dimensions'. The table should not have any relationships to other tables (this is similar to the Parameter Table pattern.
Change your measures to apply a virtual relationship whenever something is selected on the 'All Dimensions' table, to properly filter the fact table:
SUM('factSale'[Freight])
would become:
SWITCH(
SELECTEDVALUE('All Dimensions'[DimensionId]),
"categoryid", CALCULATE(SUM('factSale'[Freight]),
KEEPFILTERS(TREATAS(VALUES('All Dimensions'[MemberId]), 'factSale'[CategoryId])),
"custid", CALCULATE(SUM('factSale'[Freight]),
KEEPFILTERS(TREATAS(VALUES('All Dimensions'[MemberId]), 'factSale'[CustId])),
"empid", CALCULATE(SUM('factSale'[Freight]),
KEEPFILTERS(TREATAS(VALUES('All Dimensions'[MemberId]), 'factSale'[EmpId])),
// ... etc. for all dimensions ...
, // Fallback, when nothing is selected on 'All Dimensions'
IF(NOT ISFILTERED('All Dimensions'[MemberId]),
SUM('factSale'[Freight])
)
)
Put the [DimensionId] column into a slicer and use the [MemberId] column as the axis on your bar chart. Note that the chart will not show anything unless exactly one item has been filtered on the [DimensionId] slicer.
Explanation: The SWITCH statement determines if any selection has been made on the [DimensionId] column of the 'All Dimensions' table. In that case, a filter is applied to the fact table, depending on which dimension has been selected, using the TREATAS function. We're using KEEPFILTERS to make sure that any existing filters made directly on the individual dimensions are kept as-is.
In case no selection has been made on the [DimensionId] column, we want to fall back to the standard measure SUM('factSale'[Freight]) but since we don't want to repeat this measure for all items on the [MemberId] column, we use IF(NOT ISFILTERED( ... to make sure that we return only a blank value, if [MemberId] is currently used on the chart axis.

Power BI - DAX query to remove duplicated rows in SUM calculation

My scenario is this: SalesValue have been entered for multiple sessions namely Lunch, Breakfast, dinner which is grouped by SessionKey in numbers. The same SalesValue repeats at times for 2 or more sessions for a given production plan date, based on MenuKey, RawMaterialKey and IngSFKey.
I need to use DAX query in Power BI to remove duplicated SalesValue based on ProductionPlanDate and SessionKey for a particular MenuKey in a given date.
I have attached the screenshot of a sample value range of SalesValue containing duplicate values for the same date across different sessions for your reference. For example, rows 7 and 14 have the same ProductionPlanDate, SessionKey, MenuKey, and SalesValue.
So you have a table with one "Grain" and you want to change the "Grain" by using a subset of the columns. Specifically you want only rows with distinct columns ProductionPlanDate, SessionKey, MenuKey and SalesValue
To do this in a DAX query you would use
evaluate
summarize
( 'table name'
, 'table name'[ProductionPlanDate]
, 'table name'[SessionKey]
, 'table name'[MenuKey]
, 'table name'[SalesValue]
)
You could provide this to create a calculated table or provide it to each measure that needs to work with this coarser grained data set.
However as it seems you are in Power BI the more appropriate place to do this would be to create your coarser grained table using Power Query (via the Edit Queries section of Power BI).
This is better than doing it in DAX as DAX is more tuned to analytics where Power Query is tuned to data transformation - and you want to do data transformation.
You can either keep the table that you have now alongside the new modified or replace it accordingly.
option A will just change your incoming table to have the new coarse grain.
option B will keep your original table and have the new grained table alongside it. Note that this will mean any Power BI visuals that you have created will need to be "rewired" to use the new table.
To do the transform in Power Query, the steps for both options are
Go to the Edit Queries area on PowerBI
Select the columns that you want to create the new Grain (i.e. ProductionPlanDate, SessionKey, MenuKey and SalesValue) by holding ctrl and clicking the column headers of each column in turn.
Right click on the column header for one of the selected columns and select "Remove Duplicates"
If you want option B, simply first copy the existing table by using "Reference" then do the same thing as follows:
Find your existing table on the left Queries section, r-click and click Reference
Rename the new table something appropriate
Apply the transform steps to the new table as above
Click Close & Apply and rewire any existing visuals that you need to use the new table
If you find you don't need your old table you can R-click on it in Power Query again and uncheck "Enable Load" so that PowerBI will not see it anymore.