Change the slicer state on clicking a button - powerbi

I have 4 buttons that indicate different ranges and a slicer in my report. I want to change the slicer value according to the button I click.
Is it possible to change the value of the slicer on clicking the button?

You can do this in Power BI by applying bookmarks to slicer and add those bookmarks in action property of buttons. In Power BI Embed you can apply buttonClick event to the button and set the state of slicer but that event will be triggered for all the buttons in the report. Instead of having 4 buttons you can use only one button and set slicer state according to the number of times the button is clicked. To change the state of a slicer on clicking a button in an Embed report, Please find the below code snippet:
Set the Filter config:
const filter = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table_Name",
column: "Column_Name"
},
filterType: models.FilterType.Advanced,
logicalOperator: "And",
conditions: [
// Add condition here as per your requirement
]
};
Get the current active page:
const pages = await report.getPages();
// Retrieve the active page.
let page = pages.filter(function (page) {
return page.isActive;
})[0];
Get all the visuals:
const visuals = await page.getVisuals();
Find the slicer:
let slicer = visuals.filter(function (visual) {
return visual.type === "slicer" && visual.name === "Visual_Name";
})[0];
Add the button click event and set the state of slicer:
report.on("buttonClicked", function (event) {
slicer.setSlicerState({ filters: [filter] });
});
Pleaser find references here:
https://learn.microsoft.com/javascript/api/overview/powerbi/handle-events#buttonclicked
https://learn.microsoft.com/javascript/api/overview/powerbi/control-report-slicers#set-slicer-state

Make 4 copy of slicer and select different value in each slicer. Now select the Bookmark and selection pane from ribbon and hide all 3 slicer and keep one visible. And then select the property of the button and in Action , choose Bookmark and name of bookmark created above.
Same thing you need to do for other 3 buttons. Each time selecting a new slicer.

Related

Get Select list Item value in IG report column for DML operation

I have a Select list filter on the top of the page. I want its return value to get into any column which I create in IG report automatic DML process.
Suppose, Select list has a value "Step", when I add a row in IG report, that value should be saved into DB for one column which is hidden on UI.
I tried but sometimes it stores the value which I selected in Select list item as my last selection not the current one. Do I need to create Application item for this? Please help. TIA
In this case there is a table ig_tickes with a status column. On the page there is a page item P131_STATUS (select list) with values "OPEN" and "CLOSED". There is an interactive grid on table ig_tickets with column STATUS hidden. Functionality is that user selects a value from the select list and then clicks "Add Row".
Give the interactive grid a static id of "tickets"
Create a dynamic action on change of P131_STATUS with a true action of type "execute javascript code" and code:
var model = apex.region("tickets").call("getViews").grid.model;
model.getOption("fields").STATUS.defaultValue = apex.item( "P131_STATUS" ).getValue();
That's all there is to it.

Added slicer to filter project engineer and it did not update the budget number

So I am trying to filter an element called budget by project manager and project engineer. I added a slicer to filter my project engineer and it did not update the budget #, which is a sum. However, when I went into excel and imported data and filter it works. Any idea?
Sometimes Values get updated but DOM will not be updated. Follow the below steps
1.Create a const filter
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "table_name",
column: "column_name"
},
operator: "operator",
values: ["values"]
};
2.Get the Pages and Active Visuals
const pages = await report.getPages();
// Retrieve the active page.
let page = pages.filter(function (page) {
return page.isActive;
})[0];
const visuals = await page.getVisuals();
3.Get the slicer and set Slicer state
// Retrieve the target visual.
let slicer = visuals.filter(function (visual) {
return visual.type === "slicer" && visual.name === "4d55baaa5eddde4cdf90";
})[0];
// Set the slicer state which contains the slicer filters.
await slicer.setSlicerState({ filters: [filter] });
console.log("Date slicer was set.");
}
If the DOM is not updated, use updatefilters so it will make report to render again
await pages[0].updateFilters(models.FiltersOperations.Add,[filter]);
References:
https://learn.microsoft.com/javascript/api/overview/powerbi/control-report-filters
https://learn.microsoft.com/javascript/api/overview/powerbi/control-report-slicers

Expand or collapse navigation pane in Power BI Report

I have implemented the navigation pane feature in Power BI report as shown below. I like to expand or collapse this navigation pane to utilize page for visuals.
Is there any visuals/tricks to do this?
You can save your report/page layout as a bookmark (Menue Bar > View > Bookmarks Pane) with the navigation pane visible (NavigationVisibleBookmark).
You can trigger visuals visible/invisible with the eye symbol in the selection pane (Menue Bar > Views > Selection Pane`).
Then save another bookmark with the navigation pane invisible (NavigationInvisibleBookmark).
Now you can trigger the two different bookmarks with a button for example. Add a blank button and go to the Properties > Action and choose Type = Bookmark and Bookmark = NavigationVisibleBookmark.

How to only display 'Edit' link on certain rows on apex interactive grid?

I have an interactive report apex5.0 which contains several fields.
Would like to disable 'edit' pencil option link where payment_date & code is populated.
Link is to be enabled only where payment_date & code is null.
Disable the edit button for a particular row, based on a specific value in its column.
For ex. If a grid has 3 columns A,B,C and if B contains "Apple", and '01-jan-17', the edit button for that row must be disabled.
What are the different options to do this kind of functionality in apex5.0, enable & disable "EDIT" based on certain criteria?
You could also add a case statement to your report's query.
E.g.
(Case when [some logic] then
--display link
'<img src="#IMAGE_PREFIX#menu/pencil16x16.gif" alt="" />'
End) as col_link
The above example will only display a link if the case statement is met. The link will point to page 47 and we will pass the query's Id column to page 47's item P47_ID
In order to treat this new column as a link you must change the "display as text" property to "standard report column"; you can achieve this when editing the report attributes.
One way is to use JavaScript on page load:
Let's asume that first column is with ID and used to show edit link. Second column is your product name like Apple. Just disable click on this element(cell with ID) or change link, img etc.
var table = $(".a-IRR-table tbody");
table.find('tr').each(function (i, el) {
var $tds = $(this).find('td'),
productId = $tds.eq(0).text(), //first column with ID and edit link
product = $tds.eq(1).text(), //second column
Quantity = $tds.eq(2).text(); //third column
if (product == 'Apple'){
$tds.eq(0).click(false);
$tds.eq(0).replaceWith('');
}
});
Thanks to this answer for JavaScript: Loop Through Each HTML Table Column and Get the Data using jQuery
EDIT:
To hide value based on your Query use CASE. For example:
SELECT
CASE
WHEN B = 'Apple' THEN
'<img src="#IMAGE_PREFIX#edit.gif" alt="">'
ELSE ''
END edit_link,
A,B,C
FROM TABLE_NAME
Click on column edit_link and make it of type Link
Choose your target to edit page
For link text select #EDIT_LINK#
Escape special characters must be set to NO
On Report Atributes set **Link Column** to **Exclude Link Column** (you have custom link column so don't display original link)
*Check your online workspace, page 3*

Refresh Apex 5.0 chart results with different dynamic actions on same SQL query

I have created a bar chart on APEX 5.0 where my query looks like below:
select col1 as label,col2 as value from table1 where :P3_NEW_1 = col3;
here: P3_NEW_1 the page item I have created of type "Select List".
The list of values in "Select List" page item are pre-populated in the dropdown using the "Shared component" type I have created and so far this worked fine and I am able to display the results of above query by passing the value through the page item select list.
Now I need to add 2 data pickers on the same Apex page such that I should now be able to filter the results using date picker through dynamic action.
I know that using an additional button I can create a dynamic action but my problem is how do I modify the above query such that following should happen.
During the page load, once I select a particular value from the "Select List", it should display records based on the value selected from dropdown
This I already achieved using above sql query for the bar chart.
Once the bar char is displayed, I should next be able to filter and display the results using date ranges through date pickers.
Here my problem is my bar chart query is same but I need to now pass the start_date and end_date to the same above sql query which but I am not sure how to achieve this. If I add a button for dynamic action I need to select the report region which is the "bar chart" region and here my query needs modification.
Once the bar chart display the results, at the next step how do I filter the results by having the date filters with dynamic action on the same region where bar chart was displayed. How to achieve this?
You can change the query to something like this:
SELECT COL1 AS LABEL,
COL2 AS VALUE
FROM TABLE1
WHERE :P3_NEW_1 = COL3
AND (:P3_START_DATE IS NULL
OR TO_DATE(TIME_STAMP,'YYYY-MM-DD-HH24:MI:SS') BETWEEN :P3_START_DATE AND NVL(:P3_END_DATE,SYSDATE));
Where :P3_Start_date and :P3_End_date are the Start and End date pickers and TIME_STAMP is your column where you store the date.
After modifying the query you can simply add a button where at Behavior>Action select Submit Page.
This way when you click the button, the page will be submitted and chart refreshed.
If you want to take your chart to the next level you can do a partial refresh on it. Here is a short video tutorial of partial refresh on a report but you can apply the same login on your chart.