Dax measure to avoid all slicers except one in Power BI - powerbi

Here, I have a dataset in which there is an eventid (ID) captured for each event generating in each department(DEPT), with its timestamp(event-time).
Each event captured is categorized as OPEN/ CLOSE(event status).
I want to show the efficiency of each department, which is defined as-
Total cases closed Divided by Total no. of cases registered in that Department.
I tried using 100% stacked bar chart, but the result in it changes every time a different slicer is selected.
Please Help.

You'll need to use a combination of CALCULATE and ALLEXCEPT. THe resulting measure will look something like this:
NewMeasure := CALCULATE([OriginalMeasure], ALLEXCEPT('MyTable'[Field To Keep Filters ON]))

Related

In Power BI, how can I create a column that changes based on a slicer and visualization?

I'm pretty new to Power BI. I'm unsure how to approach this.
I have one visualization that displays the ten most frequently bought products in a time frame that is set by a slicer. In another visualization, I display how those products have been selling over the past few years (this time frame is not determined by the slicer). I want to display only the ten products that come from the first visualization, not the ten most common over the time frame in the second visualization.
How can I accomplish this? The approach I have in mind (and I'm open to others) is to create a true/false column that changes with the first visualization. "True" would be for products that are frequently bought as determined by the first visualization in the slicer-determined time range, and the second visualization would only look at values with a "true" in that column. How can I create a column (or table, maybe?) that changes depending on a visualization?
Clarification: most of the pages will say Top10 ... Actually, the measure used was a simple Top5 that includes products with the same number of orders than the 5th product. Therefore, to avoid dealing with larger images, 7 products will be seen but it is a Top5 ranking. The idea is you can replace it with your custom TopN measure.
What I understood:
The simplification of your model plus the disconnected help table would be:
I have one visualization that displays the ten most frequently bought
products in a time frame that is set by a slicer.
The Date slicer belongs to the Dates table in the Data model.
The table viz represents the number of rows in the sales table in the
current context (for each product within the Date range).
The table viz is sorted according to the [#Rows] measure in descending
order.
The table viz only presents the TopN products even without the presence
of the [#Rows] measure due to the presence of the [TopOrders]
measure within Filters on this visual. [TopOrders] is 1.
On the second page you create:
A slicer with the Dates[Date] column (the same one used on the
previous page).
A matrix with Products[ProductName] on the rows, HDates[Year] on
the columns, and a measure on values.
From the View tab, you select the Sync Slicers option.
Inside the Sync Slicers pane:
In the Sync column, check the boxes related to the necessary pages.
In the Display column uncheck the box that contains the over
years report.
So far all we have done is pass the time frame context from page 1 to page 2.
Since the TopN context depends on the time frame context, we can now use the [TopOrders] measure as a Filters on this visual in the matrix. Again, [TopOrders] is 1.
Why do the numbers differ between rows and not between columns?
Also, in this example, the Sales table only has information up to 12/31/2020 but the visualization shows an additional year and the Sales[Amount] values for each order is $1 so that [#Orders] and [SalesAmount] are the same for easy comparison.
HDates is not related to the model and for each combination of HDates[Year]-Products[ProductName], the [SalesAmount] measure is using the information coming from the previously hidden slicer and the respective Products[ProductName] because the information coming from HDates[Year] has no effect yet.
In order to complete this exercise, it only remains to modify the [SalesAmount] measure in such a way that it removes the filter on the time frame (Dates[Date]) and it recognizes HDates[Year] as Dates[Year].
SalesAmount :=
CALCULATE(
SUM(Sales[Amount]),
ALL(Dates),
TREATAS(VALUES(HDates[Year]),Dates[Year])
)
And this is the final result.
I hope it works for someone or the idea can be improved.

Power BI / DAX return values from table from rows filtered out by slicer

I have a table visualisation that shows the populations of countries and a toggle switch that flips between 'sold' and 'unsold'. (This works with a measure that checks is a country is present in a sales table and assigns a 1 or 0 which is then used as a filter on the table visualisation).
Various slicers in the dashboard are used to filter the data model and retain the details of sales. When 'unsold' is selected therefore, the relevant countries are already filtered out of the countries data table and it is not possible to display them with their populations.
At the moment the workaround is to use a duplicate countries table that only has a one way filter, so that the rows remain regardless of filtering. This means that other slicers which interact with the rest of the data model don't filter the table visualisation as desired.
I am sure this must be possible using some combination of CALCULATE(), FILTER() and ALL() but I haven't managed to achieve this.
N.B. I can force the unsold countries to appear in a table visualisation using a constant measure (with formula: measure_name = 0) in a column .
Apologies if this is not very well explained, any help much appreciated.
Thanks for reading,
S
Image attached to (hopefully!) explain problem better.
Real scenario is more complicated hence not screenshotting from PBI.

Can a measure be created in Power BI that references two tables that share no relationship?

I'm trying to create a matrix table in Power BI to display the monthly rent projections for a number of properties. I thought I could simply create a measure that summed the rent from one table and then displayed it by month based on start and end date conditions, but it's been a while since I created any measures and I had forgotten that there needs to be a relationship between columns, among other things.
Data Model
A site can have more than one lease associated with it and a lease can have both car-parks and floors associated with it, of which there can be multiple.
In addition to the tables in the linked image, once I had sorted out what I thought would be the easy step I was going to add another table which includes the estimated percentage rent increase and the period in which the increase will occur.
I started out by trying to create a measure along the lines of the following:
Matrix Test =
IF (
HASONEVALUE ( Period[Month] ),
IF (
Period[Month] >= Leases[Custom Start Date],
SUM ( Floor_Rent[Annual Rent] ) / 12,
0
),
0
)
This would need to be expanded upon because the end date of a lease would also need to be taken into consideration.
As well as forgetting about the relationship requirements, I've forgotten how to deal with the issue of narrowing down to a single value within a column.
The result is supposed to be something that looks like this:
The blanks indicate a lease that starts in the future or ends within the time-frame displayed.
When I try linking the Leases table and the Period table on Leases[Start month for current term] and Period[Month] all I can get to is a table that shows the rent amount in the month the lease starts.
Is what I'm trying to achieve possible? If so, how do I accomplish the desired result?
Link to .pbix file
Solution
The direct answer to the title question is probably 'no', but while trying to figure out how I could use Pratik Bhavsar's LOOKUPVALUE suggestion I had a thought and performed a clumsy google search - power bi create table for each value in column - and found this post. By meddling with some of the DAX in said post I was able to come up with the following:
Test Table =
GENERATE(
SELECTCOLUMNS(
VALUES(Leases[Lease ID]),"Lease ID",[Lease ID]
),
SELECTCOLUMNS(
VALUES(Period[Month]),"Month",[Month]
)
)
The result is a table with each Lease ID mapped against each Month. I can't claim to understand exactly how the functions work, and it's not the outcome I thought I needed, but it allows me to achieve exactly what I set out to do.
I've accepted Pratik Bhavsar's answer because it effectively accomplishes the same thing as the work around I implemented. Pratik's solution might be better than what I eventually landed on, but I need to have a closer look at how the two compare.
The following DAX will give you a table with all buildings mapped against all rows in the period table, eliminating the requirement of a relationship.
SiteToPeriod =
CROSSJOIN(
SELECTCOLUMNS(Sites1, "Building name/label", Sites1[Building name/label]),
Period
)

Is it possible to use a slicer as a parameter to a DAX Summarize function?

I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.
Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.
I am using the following DAX code to do the group by like so...
Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)
I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?
If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.
To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:
Year Max =
VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
RETURN MAXX(CalculatedTable, [Losses By Year])
Writing it this way will allow the calculated table to respond to your slicers and filters.

how to ignore all slicers except date slicer and get count in power BI

I would like to get count of order number and I have multiple slicers which would slice down the value . for one calculation .I would need to ignore all the other slicers except date slicer and get the count of orders.could you please help.
If you want to ignore all the slicers, you can create a measure using the DAX function ALL. And if you want to ignore all the slicers except one, you can use ALLEXCEPT. Those two function will calculate your count based on all the values.
If you have a visual that only shows the count you are referring to, there is another way. You can stop slicers from interacting with the visual you want your count to appear on. So, you can select the slicer, go to Format and the click Edit Interactions and clik the circle (None interaction). Do the same for all slicers you don't want to affect the visual with your count.