Toggle between different "Show Values As" options in Slicer - powerbi

I am using a Matrix in PowerBI to show the Sales Manager and Sales Reps down the rows, and the different ship method and source of the order across the columns and a count of unique orders in the values.
Below shows the table structure I have, and I want to switch between "Show Values As": the original values I calculate with my measure (count of unique orders) and % of Row Total.
Currently, my only solution is to create a second table showing the different values, but I think that's a cheap solution. I've seen solutions with helper tables but since my values are a measure I cannot invoke them in other measures, and as the sources or ship methods are filtered I want the % of row total to reflect the filter as well so using a countx formula won't account for that (if I housed it in a formula).
I'm still somewhat new to the software so please bear that in mind.
Source 1 | Source 2 | Source 3
| Next Day; Ground; 2 Day | Next Day; Ground; 2 Day | Next Day; Ground; 2 Day
+Manager 1|
Rep 1 |
Rep 2 |
+Manager 2|
Rep 1 |
Rep 2 |

Looks like the best solution for you is to create bookmarks. You can create two tables, one showing the values and the other showing the %. Position the tables such that, one table is exactly on top of the other. Then create two bookmarks, one showing Table1 and the other showing Table2 (while hiding the other table using the "Selection Pane"). You can then use the bookmarks in a button action to toggle between Value and % views. The following link should give you further details on bookmarks:
https://learn.microsoft.com/en-us/power-bi/desktop-bookmarks
You can also do this by creating a measure which switches between values and %, but the formatting is going to be a pain point. I think bookmarks is your best bet.

You can create a parameter table (with no relationships to other tables in your model) to use as a slicer and a measure that switches between the two calculations based on a slicer selection.
Let's suppose you have measures [OrderCount] and [OrderCount%Total]. Then create a new table to use as a parameter ParamMeasure with a single column
Measure
-------
Count
%Total
You can now put ParamMeasure[Measure] as a slicer on your report and substitute the following measure instead of the existing ones.
OrderSwitch =
IF (
SELECTEDVALUE ( ParamMeasure[Measure] ) = "Count",
[OrderCount],
[Order%Total]
)
This way you don't need to create multiple visuals and bookmarks.

Related

Power BI - Need a slicer to look at multiple columns of Data

I am learning PowerBI as i go along and have been able to solve most issues faced by a quick google. Unfortunately this problem has baffled me.
We have thousands of lines of data which include a "Home Country" column & "Away Country" column.
What we need our slicer to do is to is to pick up for example Australia in both of these columns and display the results.
I currently have a table created using the below:
slicercountrytable = distinct(
Union(
Values('All Data'[Home Country]),
Values('All Data'[Away Country])))'''
and then a measure:
Measure =
if(
Min('All Data'[Home Country]) in values (slicercountrytable[Country])
|| Min('All Data'[Away Country]) in values (slicercountrytable[Country]),
1,
Blank()
)
And have also tried the below measure:
Measure 3 = VAR
Searchvalue=search(SELECTEDVALUE(slicercountrytable[Country]),SELECTEDVALUE('All Data'[Combined Country]),,Blank())
Return
If(Searchvalue > 0,"Found")
I need the slicer to control the entire sheet however the above are doing nothing.
Thanks
In that case, instead of building some complicated DAX I suggest to work the model.
Let's say your current table looks like that:
id
home country
away country
1
A
B
2
B
C
You may want to deal with that in another table by unpivoting home_country and away_country in PowerQuery.
In order to have a country table like that:
id
country
attribute
1
A
home
1
B
away
2
B
home
2
C
away
Then you link this new table to your existing one on id and filter/slice in it.
I reproduced your example and feel that it is already showing the desired behavior. I think the problem you might be running into is that you will now need to add your 'measure' filter to each and every visual individually. It cannot be added to 'Page' or 'All Pages' filter areas. This is because of the way a measure's calculation varies across context and cannot be avoided.
DAX
Table 2 = distinct(union(all('Table'[Away]), all('Table'[Home])))
Measure =
if(
MAX('Table'[Away]) in VALUES('Table 2'[SelectedCountries])
|| MAX('Table'[Home]) in VALUES('Table 2'[SelectedCountries]) ,
1,
blank()
)

Power BI calculate sum only last value of duplicate ID

I'm struggling to create a Measure that sums a column and have it filter out duplicate IDs while taking only the latest row.
For example, there is a table as such:
UID | Quantity | Status | StatusDate
aaa | 3 | Shipped | 11/1/2020
aaa | 3 | Delivered | 11/5/2020
bbb | 5 | Ordered | 10/29/2020
ccc | 8 | Shipped | 11/4/2020
So the idea would be to sum the quantity, but I would only want to count quantity for id "aaa" once and only count towards the latest status ("Delivered" in this case). I would make a visual that shows the quantities with status as its axis. I also need to add a date Slicer so I could go back in time. So, when I go before 11/5/2020, instead of "Delivered," it would switch back to "Shipped."
I tried several methods:
SUMMARIZE to a table filtering "MAX" date value if UID is the same. I found this doesn't work with the date slicer since it seems like it is not actually recalculating the filtering and just slicing away rows outside of the dates. Seems to be the same whether the SUMMARIZE is set as a new table or VAR in the Measure.
CALCULATE seems promising but I can't seem to figure out a syntax
that filters that I need. Example of one that doesn't work (I also tried SUMX instead of SUM but that doesn't work either):
CALCULATE(
SUM(Table1[Quantity]),
FILTER(Table1, [StatusDate]=MAXX(FILTER(Table1,[UID]=EARLIER([UID])),[StatusDate])
)
I also tried adding a column that states whether if the row is "old" as well as a numerical "rank" to the different statuses. But once again, I run into the issue where the date slicer is not exactly filtering to recalculate those columns. For example, if the date slicer is set to 11/3/2020, it should add "3" to "Shipped" instead of "Delivered." But instead of that, it just removes the row which tells me that it is not actually recalculating the columns (like #1).
Any help would be appreciated :-) Thank you!
You can try something like this:
Measure =
VAR d = LASTDATE(Table1[StatusDate])
VAR tb = SUMMARIZE(FILTER(Table1, Table1[StatusDate] <= d),
Table1[UID],
"last", LASTDATE(Table1[StatusDate]))
RETURN CALCULATE(SUM(Table1[Quantity]), TREATAS(tb, Table1[UID], Table1[StatusDate]))
The tb variable contains a table which has the latest date per UID. You then use that to filter your main table with the TREATAS function.
One other alternative is to create a table with the RANK function ordered by date and then doing a SUM over that table, where Rank = 1.

Power BI - Select Slicer Date Between 2 Columns

Hopefully a quick explanation of what I am hoping to accomplish followed by the approach we've been working on for over a year.
Desired Result
I have a table of SCD values with two columns, SCD_Valid_From and SCD_Valid_To. Is there a way to join a date table in my model (or simply use a slicer without a join) in order to be able to choose a specific date that is in between the two SCD columns and have that row of data returned?
Original Table
ID | SCD_Valid_From | SCR_Valid_To | Cost
1 2020-08-01 2020-08-03 5.00
Slicer date chosen is 2020-08-02. I would like this ID=1 record to be returned.
What We've Attempted So Far
We had a consultant come in and help us get Power BI launched last year. His solution was to create an expansion table that would contain a row for every ID/Date combination.
Expanded Original Table
ID | SCD_Valid_Date | Cost
1 2020-08-01 5.00
1 2020-08-02 5.00
1 2020-08-03 5.00
This was happening originally on the Power BI side, and we would use incremental refresh to control how much of this table was getting pushed each day. Long story short, this was extremely inefficient and made the refresh too slow to be effective - for 5 years' worth of data, we would need over 2000 rows per ID just to be able to select a dimensional record.
Is there a way to use a slicer where Power BI can select the records where that selected date falls between dates in two columns of a table?
Let me explain a workaround and I hope this will help you to solve your issue. Let me guess you have below 2 tables-
"Dates" table with column "Date" from where you are generating the date slicer.
"your_main_table" with with column "scd_valid_from" and "scd_valid_to".
Step-1: If you do not have relation between table "Dates" and "your_main_table", this is fine as other wise you have to create a new table like "Dates2". For this work around, you can not have relation between those tables.
In case you have already relation established between those tables, create a new custom table with this below code-
Dates2 =
SELECTCOLUMNS(
Dates,
"Date", Dates[Date]
)
From here, I will consider "Dates2" as source of your Date slicer. But if you have "Date" table with no relation with table "your_main_table", just consider "Dates" in place of "Dates2" in below measures creation. Now, Create these following 4 measures in your table "your_main_table"
1.
date_from_current_row = max(join_using_date_range[SCD_Valid_From])
2.
date_to_current_row = max(join_using_date_range[SCD_Valid_to])
3.
date_selected_in_slicer = SELECTEDVALUE(Dates2[Date])
4.
show_hide_row =
if(
[date_selected_in_slicer] >= [date_from_current_row]
&& [date_selected_in_slicer] <= [date_to_current_row]
,
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "your_main_table"
Final Step: Now just add a visual level filter with the measure "show_hide_row" and set value will show only when "show_hide_row = 1".
The final output will be something like below image-

How to use a Power BI slicer to filter two column of a table

I have a table of Enter and Exit time of some people like this:
Name | EnterTime | ExitTime
=============================
Tom | 13:52:00 | 20:55:00
Robert | 15:55:00 | 21:12:00
Sarah | 19:08:00 | 19:48:00
Jack | 16:54:00 | 17:32:00
I want to show the user that in a selected point of time who has presence.
In other word, I want to have a dateTime slicer that the user will pick a time and then the table got filtered to show only rows with:
EnterTime < selectedTime < ExitTime
This can be done with a few steps.
First, we need a list of dates to go into our slicer. If you're using a separate date table, then that's a great source. Otherwise, you can build one with DAX that will contain all the dates in your EnterTime and ExitTime columns.
Click on 'Create Table' in the modeling ribbon. Put in the following DAX:
DateListTable = UNION(
SELECTCOLUMNS('MyTable', "DateList", 'MyTable'[EnterTime]),
SELECTCOLUMNS('MyTable',"DateList", 'MyTable'[ExitTime])
)
You now have a slicer and a table visual. Select the slicer and then navigate into the Format Ribbon (it's only available when the visual is selected. Use Edit Interactions to turn off the Slicer's filtering on the table. Set it to no interaction (the circle with a diagonal line through it).
Create a new measure
ShowDate =
VAR SelectedDate = SELECTEDVALUE('DateListTable'[DateList], BLANK())
Return
if(SelectedDate >= Max('MyTable'[EnterTime ]) && SelectedDate <= max('MyTable'[ExitTime]), 1, 0)
Finally, filter your table visual on the new measure, ShowDate, for when it is 1.
So, we create an independent slicer with a complete list of dates. But we break any filter relationship between it and the table. Instead, we use 'SelectedValue' to capture the value chosen from the filter, and create a dax measure that shows '1' when the value in the filter is between EnterTime and Exit time. Filter on that dax measure, and we get our desired behavior.

Filter by last not blank date in Power BI

I have data from multiple countries on a monthly basis. Since the updates are not regular, I want to set up filter to visuals, so they would show the last month for which I have data from all the countries. I have data from each country loaded into a separate dataset, which then are merged into one big. Is there an easy way to place such filter? I managed to use "LASTDATE" function in each of country sets to find which date is last, but if I try to filter with that measure, I simply get nothing in a result. Thanks!
Well, this feels a little clunky to me but I believe it will work for you. There are two steps. The first is to create a summary table that reads through your data and counts the number of distinct countries that you have in each month. This will be a new table in your model, so go into the modeling tab, click 'New Table' and add this DAX. Obviously, correct for your table and column names.
SUMMARIZED_ROWS = SUMMARIZE(
'Table1'
,Table1[Month]
,"CountOfCountries"
,DISTINCTCOUNT(Table1[Country])
)
Now add a measure to the table (or anywhere) like this:
MonthWithMostCountries = CALCULATE(
LASTNONBLANK(SUMMARIZED_ROWS[Month], 1 )
, FILTER(SUMMARIZED_ROWS, SUMMARIZED_ROWS[CountOfCountries] = MAX(SUMMARIZED_ROWS[CountOfCountries]) ) )
This is going to give you the month where you have the most distinct countries in your data. You'll want to look at it in a card or similarly isolated visual as it is a measure and can be affected by filter context.
So, on the left is my mock data - 3 countries, 3 months each with a 1 month stagger. On the right you see the result of the Summarize table. Then the measure showing the final result.
Hope it helps.