I'm quite new to Power BI. I have one lookup table and multiple fact tables and their relationships are all one to many.
I want to create a slicer using category desc column from my lookup table. The slicer is going to filter both category desc and old category columns in a table. Also it is filtering other visuals as a normal filter.
For example if you select golf, the table is going to show category = golf or old category = golf.
Is it possible to just use the slicer from the lookup table which would act as a normal slicer (filtering category desc in my other visuals) while at the same time filter this specific table visual based on the criteria above? Appreciate anyone's help!
|Category Desc |Old Category |Type |Amount|
|Golf |Tennis |J |11 |
|Tennis |Golf |K |12 |
|Social |Fitness |J |44 |
|Fitness |Social |K |32 |
|Golf |Other |K |23 |
|Other |Social |J |26 |
If you want to filter only one specific table, then consider using a measure. Something like this.
PickThis =
var _FilterSelect = SELECTEDVALUE('LookupTable'[Label])
return
calculate( countrows('SpecificTable'), FILTER(ALL('SpecificTable'[Category], 'SpecificTable'[OldCategory]), 'SpecificTable'[OldCategory]= _FilterSelect || 'SpecificTable'[Category] = _FilterSelect ))
Related
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.
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.
How to capture slicer value by DAX measure in all circumstances? Let's have sample data:
+-----------+---------+-------+
| category | species | units |
+-----------+---------+-------+
| fruit | apple | 1 |
| fruit | banana | 1 |
| vegetable | carrot | 1 |
| vegetable | potato | 1 |
+-----------+---------+-------+
I added two measures:
Measure 1:
species selected = SELECTEDVALUE(Table1[species])
Measure 2:
IsFiltered = ISFILTERED(Table1[species])
Case 1. All items in both slicers selected.
Case 2. (problematic case). Fruits selected and Carrots selected (it is possible when we untie slicers interactions).
In case when we select fruit category from one slicer and carrot from another slicer there is a problem. This set of items is obviously empty. However definitely carrot from species have been selected and it is confirmed by IsFiltered measure which evaluates to True. Is there a way to capture that value in DAX measure?
Since both the category and species slicers come from columns on the same table, if you have both fruit and carrot selected, then the resulting table is empty and any measures (except ones that remove both filters) will therefore be working with blanks. You cannot have both filters apply simultaneously an expect them to act independently (even if the two slicer visuals don't cross-filter).
If you don't want your species selected measure to be influenced by category, the simplest thing to do would be to turn off filtering (under Format > Edit interactions) from the category slicer to the visual containing species selected.
This isn't always what you want though, so another possibility is to create a new table for the species slicer which has no filtering relationship from Table1. This will allow you to work with the slicers selections separately if that's something you need to do. (I've definitely had to do this before when I wanted a slicer to behave more like a parameter than a filter.)
Edit: To do what I suggested, create a new Table2 in the query editor that references Table1, remove all columns other than species and remove duplicate if necessary. You should now have a single column table that is a list of unique species.
When you close and apply, Power BI will likely automatically create a relationship between the two tables, but you need to make sure it's exactly what you want. It needs to be a many to one relationship with a single filter direction.
Once this is done, you'll need to replace the Table1[species] slicer with Table2[species] slicer as well as change references in measures where necessary.
I have a dataset more or less like this one:
DATE | VALUE
01/01/2011 | 100
02/01/2011 | 150
02/01/2011 | 550 --> Repeted on purpouse
.
.
12/01/2016 | 320
Now I need to have a calculated measure with only the values within a date range, I tried in many ways but with no success, the only one I managed to get it work is the follow DAX syntax:
consuntivo = CALCULATE(SUM(provadat[valori]);provadat[datazione]>=DATE(2015;01;01)&&provadat[datazione]<=DATE(2016;01;01))
but it generates the following:
So basically I need a DAX Query with distinct sum for each dates. How can I achieve that?
Two methods.
In the Table visualization you can choose Sum as the summarize option for the column valori.
Or using DAX, it'll be just simple as
consuntivo = SUM(provadat[valori])
You don't need to handle the date logic particularly because Power BI will handle it based on the context (data columns you used with the measure).
So basically what I was missing was to add filters.
xxx = Calculate(SUM(provadat[valori]);FILTER(VALUES(provadat);provadat[datazione] <= DATE(2017;01;01) && provadat[datazione] >= DATE(2016;01;01)))
I have a column with the following data
| spoon
| fork
| fork & spoon
I would like to add a slicer to my page that has two options: Spoon, fork.
When Spoon is selected it shows the result for the rows for Spoon and fork & spoon. When Fork is selected it shows the result for the rows for Fork and fork & spoon
Can this be achieved in powerbi?
If not directly, I was thinking that formatting my data like this could help perhaps? Does powerBI have an option to see values divided by semicollons as multiple values?
| Spoon
| Fork
| Fork ; Spoon
EDIT:
Bit more info on my actual table layout:
| Service A | revenue | category 1
| Service B | revenue | category 2
| Service C | revenue | category 1 & 2
It can be achieved depending on the result you want to show for the filtered rows, e.g, a sum, average, count, etc.
I will show you a very simple example of a sum for the filtered rows by using the SUMX function available in DAX expressions.
Suppose you have two tables like this:
MyTable: Table with the data.
SlicerTable: The table used for creating the slicer.
Add a slicer to your report using the SlicerTable[SlicerColumn] column. Then create a measure called Result in the MyTable table with the following expression:
Result =
SUMX (
FILTER (
MyTable,
[MyColumn] = FIRSTNONBLANK ( SlicerTable[SlicerColumn], 0 )
|| FIND ( FIRSTNONBLANK ( SlicerTable[SlicerColumn], 0 ), [MyColumn], 1, -1 ) > -1
|| NOT ISFILTERED ( SlicerTable[SlicerColumn] )
),
[Value]
)
Don't get scared for this DAX expression, it bassicaly check if the MyColumn column contains any of the values selected in the slicer, if there is no selection in the slicer it will sum up all values of [Value] column.
Using a matrix or any Power BI visualization with the MyColumn column and the Result measure, you will get something like this:
UPDATE Alternative support for slicer without a required measure using explicit relationships and adding tables.
I've added two additional tables to your model in order to support your slice requeriment. You will have to create an additional table for supporting many to many relationship and other to get the unique category values.
Data
When you add a slicer using CategorySlicer[Slicer] column, it will automatically filter the Service table because of the explicit relationships that exists between the underlying tables.
If you get stuck creating the required tables, there is a couple of DAX expressions I have in mind to create them.
Also be sure the Cross Filter Direction relationship property is set to Both in every relationship.