Struggling with PowerBI slicer logic and process - powerbi

I've tried to be "clever" setting up a slicer for improved visual experience, but it is not working as expected.
The slicer is based on a manually created table with two options:
This leads to a slicer which is compact and intuitive for report users (multi-select allowed):
I can then create a couple of measures that record all possible truth states of the slicer, e.g.
HideInactivePathSelected = --Truth status of slicer selection
IF (NOT ISFILTERED(SlicerHideOption),FALSE, --If no slicer options selected
IF(SELECTEDVALUE(SlicerHideOption[Options]) = "Hide inactive/former pathologists",TRUE, --Specific option selected
IF(COUNTROWS(VALUES(SlicerHideOption)) = 2,TRUE, --If both slicer options selected
FALSE --If all else fails
) ) )
This can be confirmed using a simple table, which updates instantly and correctly when the slicer is changed e.g.:
The problem is, at this point, if I try to refer to the state of the measure HideInactivePathSelected, things no longer work.
For instance, if I create a calculated column that refers to the measure state, this does not work. Consider this simplified example:
test_value =
IF([HideInactivePathSelected] = True, 2, 0)
If I then make a test table or chart based off test_value, changing the slicer has absolutely no effect.
I suspect I have tried to be "too clever" and perhaps I have misunderstood the (non)dynamic nature of calculated columns. Can some kind soul tell me what I have done wrong? Is this approach salvagable or do I need to start again?
Using PowerBI RS Desktop May 2021 edition.

Measures in calculated column do not see the row context, so you have to do context transition using Calculate function, e.g.:
test_value =
IF( CALCULATE( [HideInactivePathSelected] ) = True, 2, 0)
It should be easier to solve your issue if you provide some example data. There are better and more efficient ways to achieve the goal of filtering data in whole page, than using the measure and then calculated column.

Related

PowerBI - Draw Line Chart with X Axis Grouped by Date (in Days), When Column contains Full timestamp?

I've been trying to figure this for several hours now.
In my SQL table I have a full timestamp column, with date and time of the action, e.g. last time a user was logged in.
Say I have two users who logged in today so far, in different hours. I want to see "2" log ins for today's Date, instead of seeing them broken down further into exact timestamps.
See screenshot for example
What's the easiest way to do this?
EDIT:
Seems like the whole issues stems from my desire to use "Direct Query" method to load the data.
If I'm just importing the whole table (as users_table (2)), Then yes, I can create a new column with this syntax:
Column = 'users_view (2)'[last_active].[Date]
And plot the graph that I Want.
However, I am unable to create this column on direct query mode. Trying to create this column leads to an error:
Column reference to 'last_active' in table 'users_view' cannot be used
with a variation 'Date' because it does not have any.
If such basic functinoally is not possible, then what's the merit of Power BI? my use case is to create a REAL time dashboard.
Seems like if I want to have anything in real time, it means I can't build even the most basic graph, and vice-versa.
So either I'm missing something, or Power BI is worthless for real time reporting.
You need to follow these steps:
In your fact table, create a new column that corresponds to the date of the timestamp (this will be a grouping dimension column for your timestamps)
Add a measure that counts rows of your table
In a new chart, e.g. line chart, bar chart, whatever - use the date column as X-axis information, and the row count measure as your Y-axis information
Edit: Since it is now apparent you insist on using Direct Query for this - it would appear your data is not in the correct format to support what you want to do. The solution would be to provide Power BI with the correct format for the analysis you want to do. Like adding a column in your SQL database table.
A very costly way of calculating "something" useful would be to do a cumulative count based on timestamp that resets daily. This will look messy but for a site with a lot of activity it will be able to plot something. But it will be slow - since obviously we are far, far away from what would constitute a "sensible" use-case for Power BI using Direct Query.
Cumulative Daily Logins =
VAR _max_time = MAX ( users_table[last_active] )
VAR _date = DATEVALUE ( _max_time )
RETURN
COUNTROWS (
FILTER (
ALL ( users_table ) ,
users_table[last_active] <= _max_time
&& DATEVALUE ( users_table[last_active] ) = _date
)
)

How can I force only two selection out of 5 available on slicer visual?

Can someone please help me get a fix for this please.
I want to let people make only two selection at a time, no more no less from the given options. The intention is to get data on matrix dynamic column based on these two selections.
Thanks
Avi
You did not make clear what the purpose of this exercise is and how the result should look like ("get data on matrix dynamic column"), but you could
Create 2 single selection slicers based on copies of your category column
Make sure they are not related to the rest of your data model
Get the selected rows via the SELECTEDVALUE() function
You may have to consider the case where both selections are the same.
This would be a feature of a slicer visual, but I don't know of any built-in or custom slicer visual that does this.
As a workaround you can show a warning and instruction to select two items, eg a big Card visual with red text and a transparent background in front of your other visuals displaying a measure like:
AreTwoCategoriesSelected =
IF (
DISTINCTCOUNT ( DimProductCategory[ProductCategoryName] ) <> 2,
"Select 2 Categories for this report",
""
)
Which might look like
and
You can't easily use the trick where you have the measure conditionally return BLANK because most evaluations of the measure will have a filter context with just one of the selected values.

How do I hold a slicer selection static in Power BI / DAX?

I can illustrate the issue here in Power BI. I need the selection on Date to stay static.
We audit widgets every day and look for certain quality control "issues". I have a slicer on Audit Date, and a calculation meant to return the Total Number of Distinct Units Audited within that date range. The correct value is 413 for May 17 - June 2.
However when I select a Quality Control Issue from the list, it changes my calculation. The calculation should NOT be affected by a selection on Issue, however it’s putting in an “Included” filter and then throwing out days where we didn’t audit a widget with that particular issue – see how 5/17, 5/20 and 5/23 dropped from the list whenever I click "Dent" in the table? However 413 correctly remains in the table.
I need the calculation to return 413, even when Issues are selected from a slicer or table. I thought I addressed the with the ALL() filter, but it's not behaving as I expected it to.
Note: I need to alter the CALCULATION – NOT the INTERACTIONS. The calculation is used outside of visuals.
Thank you.
Either turn of Visual Interactions in the report, or write a measure using the mighty CALCULATE function to ignore selected filters.
Once you've removed the filters you can re-apply any you want to keep, eg
totalunitsaudited =
var minDate = min('Date'[Date])
var maxDate = max('Date'[Date])
return
calculate(DISTINCTCOUNTNOBLANK(Audits[SerialNo]),
all(Audits),
Audits[Audit Date] >= minDate && Audits[Audit Date] <= maxDate)
Also here you need a date table. You can create one with the CALENDARAUTO DAX function:
Date = CALENDARAUTO()
When you put the slicer on the Audits[Audit Date] you've got automatic cross-filtering between the date and the Issue. With the slicer on a separate date table you can control whether filters on Audits flow back to the Date table.

PowerBI issue with visuals, asTimeline and a Table

I have asTimeline visual and below a Table. The idea is to display in the Table a Link to the specified record in another system. The problem is that I would like to show this Table only when there is exactly 1 record selected in asTimeline. Generally, the filtering works fine, but the table should be shown when there is only 1 element in it, and hidden otherwise.
Currently it is something like this:
Now, I have tried using the solution with a Transparent measure, similar to this. Tbe problem is that it doesn't work, the background of the table visual doesn't change when changing the selection (it is not a color problem, I have tried others). The question is whether the ISFILTERED is triggered at all when changing the selection?
Currently I have Make Transparent measure defined as
Make Transparent = IF(ISFILTERED(Table[Id]), "Red", "Blue")
and in asTimeline I have column Id specified as Entity.
I have a different idea about how to achieve that, It does not hide objects but uses a measure that returns values only when there is only one value selected.
Link = SELECTEDVALUE('Table'[link],BLANK())
or
Link = SELECTEDVALUE('Table'[link],"Please select only one Id")
A different formula might be
Link = IF(HASONEVALUE('Table'[Id]), SELECTEDVALUE('Table'[Link]), BLANK() )
Put one of those measures in a table, alone, and you should achieve what you need (also format the measure as "web URL").

Sumif using page, report and visual level filters

I have two tables that are related by an ID column called 'Program_Code' (1:Many).
'Program_Summary':
Program Code = each row has a unique ID, e.g. HI-18, HI-17
Program Name = name of a program, e.g. Home Improvement
Incentive Spending = calculate(sum(Program_Data[Incentives]))
'Program_Data':
Program Code = many rows with the same ID
Incentives = incentive amount to summarize in Program Summary table
Record Status = Claimed, Pipeline or Rejected
Record Fiscal Year = 2017, 2018 or 2019
I created a Power BI table that has rows organized by 'Program Name'. Note that each program name like "Home Improvement" may have more than one code associated with it, e.g. HI-18 and HI-17 corresponding to fiscal years.
I'm hoping to summarize Incentive Spending by program name, and use page/report level filters to restrict results. The Report Level filters are:
Record Fiscal Year = 2017
Record Status = Claimed
But, the calculate(sum(Program_Data[Incentives])) filter ignores these page level filters. How do I fix this?
You created "Incentive Spending" as a calculated column. Instead, you need to create it as a measure.
Calculated columns are calculated only once - when you create them, or when you reload data. After that, calculated columns contain only static data, and can not respond to any filters.
Measures, on the other hand, are dynamic formulas that recalculate any time you change any filters.
To fix your problem, simply create a new measure from "Modeling" tab:
and add DAX code:
Incentive Spending = SUM(Program_Data[Incentives])
(no need to use CALCULATE here).
Drop this measure into a table or matrix, and it should work. Instead of page/report level filters, I'd recommend to use slicers - create a slicer for Fiscal Year, and another slicer for Record Status. They will allow you to filter the calculation with ease.
You can use:
CALCULATE(sum(Program_Data[Incentives]);Program_Data[Record Fiscal Year] = 2017 && Program_Data[Record Status] = "Claimed")
However, I do not understand why you would need this because you have 2 tables with the right link, this should give you all possibilities with the table/matrix visualization what you need to show correct results..