Search by selected Item in PowerBI - powerbi

I have a product detail table having columns publisher, author, Category and Title. I would like to create a search by where i can select it to search by author, by title or by publisher. Depending on my choice I should be able to search that item. I would like to show it in my PowerBI Report.
This is the input table
This is the output

I found a solution, I made a unique id "isbn13p" in the dim_competitor_prods table. After that made a Slicer table, with columns selection, categories and isbn. Selection column contained my filter data "author, publisher, title".
After creating the Slicer table, made a relationship, one to many between dim_competitor_prods and Slicer table.
The code for Selection table is given below.
SlicerTableAuthCatTitle =
UNION(
SELECTCOLUMNS(dim_competitor_prods, "Selection", "author", "Category", dim_competitor_prods[author], "isbn",dim_competitor_prods[isbn13p]),
SELECTCOLUMNS( dim_competitor_prods, "Selection", "publisher", "Category", dim_competitor_prods[publisher], "isbn",dim_competitor_prods[isbn13p]),
SELECTCOLUMNS( dim_competitor_prods, "Selection", "title", "Category", dim_competitor_prods[title], "isbn",dim_competitor_prods[isbn13p] )
)
Then just put a filter for Selection and another for Categories in the Report.

Related

Power BI: calculated aggregate column using related tables

I have the following two tables:
I would like to add a calculated column to the Author table showing the total number of pages in all the books the author has written.
In SQL I would solve the problem by writing a view like this (or using that code in a trigger to populate the calculated column):
SELECT
"Author"."Author ID"
(SELECT sum("Page count") FROM Book WHERE "Author ID" = "Author"."Author ID") AS "Total pages"
FROM "Author";
How to achieve something like that in Power BI?
Since you want to add the column to the dimension table (one side of the one-to-many relationship) you'll have to use RELATEDTABLE() instead of the RELATED() function:
Page Count = SUMX(
RELATEDTABLE(Book),
Book[Page Count]
)
The row context in your calculated column gets transfered to a filter context in the fact table (Books). This feature is know as context transition.
Of cause your SQL would rather return a table like this one:
Author Pages =
SELECTCOLUMNS(
Author,
"Author ID", Author[Author ID],
"Page Count", SUMX(
RELATEDTABLE(Book),
Book[Page Count]
)
)
However, if you are just interested in visualizing the numbers you don't need any of the above expressions, but just have to drag Author ID and Page Count into a Table visual.

Show filtered data when no value is selected in slicer in power bi

I have two tables, once for slicer and other one is for details table. The details table have a InvoiceDate column where some rows have blank InvoiceDate. The slicer table looks like below:
The slicer will only show value of of ID 1, like below.
Initially I want slicer to be un checked and the data should show only rows where InvoiceDate is Blank. Once User select the Slicer as Include Invoiced Records, it should show both full details i.e. Rows with Blank + Non-Empty dates rows.
There are two other ways of doing what you want that are probably more 'correct' but I'll also describe a way to provide the behavior you describe.
Option one: Delete your second table. Add a calculated column to your details table as follows:
Invoice Status = IF (ISBLANK([Invoice Date]) = TRUE(), "Not yet invoiced", "Invoiced")
Create a slicer using [Invoice Status] and simply default it to show 'not invoiced.' If users want to see the invoiced records, they just check that box in the slicer as well.
Option Two: Use Bookmarks and buttons to produce the desired effect. Create two buttons, one that says 'Include Invoiced Customers' and another that says 'Hide Invoiced Customers' -- create two bookmarks where one has the invoiced customers filtered out of the visual and one where the invoiced customers aren't filtered. Set each button's "Action" to the appropriate bookmark.
Option Three Keep your 'slicer' table. Let's assume it's called 'Invoice Filter Selection.' Create a new measure:
IncludeDetailFilter =
IF (ISFILTERED('Invoice Filter Selection'[Value]) = True(),
1,
IF (ISBLANK(MAX(InvoiceDetails[Invoice Date])) = TRUE(), 1, 0)
)
When the slicer has a selection, it will be considered 'Filtered' and you will pass into the first branch of the IF where the measure always evaluates to 1. When the slicer isn't selected, the measure will evaluate to 1 or 0 depending on whether or not there are any values for Invoice Date in the row. Add this new measure as a filter on your invoice detail visual.
Unchecked:
Checked:
Hope it Helps.

Create single slicer for multiple similar columns in Power BI

In Power BI I have an inventory with multiple possible owners for each product.
Example data:
Product
Primary Owner
Backup Owner
Widget 1
Frank
Sally
Widget 2
Sally
John
Widget 3
John
Widget 4
Frank
Anna
Desired result: to display the full inventory in a table, and provide a slicer that users can filter the table with. The slicer would be a list of all owners (both primary and backup), and when a user is selected the table would display any row where that user is present (whether they are present in the Primary Owner or Backup Owner field.
With the above example, if you were to filter by John you would see Widget 2 and Widget 3, whereas filtering by Sally would show you Widget 1 and Widget 2.
Failed attempts: Using two distinct slicers does not work for this, as it will hide data in the other column. If John were to filter to himself as Primary Owner, he would then no longer see data for Widget 2 where he is the Secondary Owner. Concatenating the Primary and Secondary together into a joined column also does not work, because I would get items like Frank|Sally or Sally|John and the combined data does not make sense for the user as an option in the Slicer.
Finally I tried creating a separate table that contains the combined list of all Primary and Secondary Owners into a single column, then relating it to the main table, however I cannot have two active relationships at once. I know Measures have access to inactive relationships through Calculate, but I don't know how (or if it is even possible) to create a slicer from that.
Edit: After re-reading your post, it would probably make sense to calculate a new table to handle this. The table will have two columns, Product and Person (or Owner in your case):
Slicer Table =
UNION (
SELECTCOLUMNS (
FILTER( 'Table' , 'Table'[Primary Owner] <> BLANK() ) ,
"Product" , 'Table'[Product] ,
"Person" , 'Table'[Primary Owner]
),
SELECTCOLUMNS (
FILTER ( 'Table' , 'Table'[Backup Owner] <> BLANK() ) ,
"Product" , 'Table'[Product] ,
"Person" , 'Table'[Backup Owner]
)
)
After this has been calculated, create a relationship between these tables, between the Product columns. Since this is purely for filtering the table on the person of interest, make it be Many-to-Many and have Slicer Table filter Table:
Create a slicer with the Person column from the Slicer Table and test the functionality:

Sorting date filter in DESC order in Power BI

I have a date filter for my dashboard and depending on which end of month date the user selects the dashboard displays the appropriate values for the selected month and all of that works correctly. However I would like my date filter to be sorted in DESC order for the user so they do not have to scroll down to the bottom to get the most recent month. I have sorted the dataset in DESC order for the query tied to my dashboard, I have gone to the DATA tab within Power BI and sorted the dataset in DESC order but no matter what I try the filter will not sort in DESC order. Any help is much appreciated.
Unfortunately in page level filters there is no option to sort date to descending order.
One option is to use a Date slicer and sort it descending.
But if you cant have date slicer then a work around is there to implement this.
For this you need to create two calculated columns. One a duplicate column of your date field and another to sort this field.
SortCol = Table[EOM Date]*-1
EOMDateCopy=LEFT([EOM Date],LEN([EOM Date]))
Sort the EOMDateCopy column with SortCol and drag EOMDateCopy in your page level filter.
Best Regards,
Shani
My suggestion is to build your own Calendar table. In "Data" View, create a new Table by writing DAX similar like this:
Calendar =
VAR _MinDate = MIN('YourFactTable'[Date])
VAR _MaxDate = MAX('YourFactTable'[Date])
VAR _BaseCalendar = CALENDAR(_MinDate,_MaxDate)
RETURN
GENERATE(
_BaseCalendar,
VAR _BaseDate = [Date]
VAR _Year = YEAR(_BaseDate)
VAR _Month = MONTH(_BaseDate)
VAR _Quarter = QUARTER(_BaseDate)
VAR _Day = DAY(_BaseDate)
RETURN
ROW (
"Calendar Year", _Year,
"Calendar Month", _Month,
"Calendar Year-Month", _Year&"-"&IF(LEN(_Month)=1,"0"&_Month,_Month),
"Calendar Quarter", FORMAT(_Quarter,"\Q0"),
"Date Order", 9999 - (_Year+_Month+_Day)
)
)
"Date Order", 9999 - (_Year+_Month+_Day) create a descending order for your date.
Next, build a relationship between your Calendar table and your Fact table by relating the "Date" column of your Calendar table and your date column (version_no in my case) of your Fact table. Make sure these two columns have exactly the same date format.
Finally, click on the column and set "Sort by column" as Date Order
You will see your date filter is sorted in desc.
Please make sure your date field is in proper format and then try to sort.
If it is already in date format, please give a bit more details so that we can check.
Best Regards,
Shani

Relationship calendar with simple facts table not showing date

Can someone please explain me why this relationship isn't working?
I have a calendar table with
ADDCOLUMNS(
CALENDARAUTO(),
...
)
Which contains a date column related to "Document date" in Table1. Both columns are "Date" type (also tried with Date/Time).
I get the following table:
The first column is "Date" from the Calendar table.
All other columns are from Table1.
Why is "Date" empty?