Impossible to show all records if parameter is not given in Power Bi Report Builder - powerbi

I've been struggling to make it work. I have a dataset with column Country and each record has its own country. I've also created a parameter #Country which is a blank input. What I want to do is to show all records from dataset if parameter is left empty and show records matching country when it is given by user. So far everything works whenever I input a country BUT when I leave it blank then no records are being shown. How can I fix it?
Snippets of code I've tried, ever one with the same result.
FILTER('Dataset', ISBLANK(#Country) || 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(ISBLANK(#Country), 1, 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(ISBLANK(#Country), 'Dataset'[Country], 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(NOT(ISBLANK(#Country)), 'Dataset'[Country] = #Country, 1))

Related

Oracle Apex 22.21 - Chart Page - Bar Type - Datepicker

I have a table ORDERS which contains column ORDER_DATE. I have created a Chart as a Bar type. I want the chart to show the amount of orders in a given date or range.
I'm following this Youtube tutorial which shows how to create a datepicker that returns a range in a Report. I'm trying to replicate this in a chart.
What I've done so far
Created datepicker items P5_DATE_FROM and P5_DATE_TO
Changed the Series Source Type to SQL Query
select ORDER_ID,
ORDER_NUMBER,
TO_CHAR(ORDER_DATE, 'YYYY-MM-DD') AS ORDERDATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where TO_CHAR(ORDER_DATE, 'YYYY-MM-DD') between :P5_DATE_FROM and :P5_DATE_TO
Source Page Items to Submit added P5_DATE_FROM,P5_DATE_TO
I basically followed the exact steps of the video. However, since the video is for a report and mine is for a chart, the chart isn't actually returning any data.
I think this is because for charts there are additional fields I need to configure. I noticed the video didn't cover Column Mapping and I'm a bit confused to what to enter here.
----------------UPDATE-------------
I've followed Koen's instructions from his answer. It seems like to TO_CHAR function was causing the error. I've updated the SQL Query to below:
select ORDER_ID,
ORDER_NUMBER,
ORDER_DATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
However, on the Page Designer I cannot save and run page until I select Column Mapping - Label and Value. I've set the Label as ORDER_DATE but I am unsure of what to select for the Value.
Setting the Value to ORDER_DATE shows an error Ajax call returned server error ORA-01403: no data found for CHART Count Orders by Date.
and selecting any other Value such as ORDER_NUMBER or ZIP_CODE populates the chart with the actual integer value of the column (ex: ZIP_CODE returns a chart of x-axis: date, y-axis: actual zip code numbers)
I see 2 possible issues.
You submit P5_DATE_FROM and P5_DATE_TO but the source has P1_DATE_FROM and P1_DATE_TO - not sure that is a typo but it should all be the same...
The where clause is wrong. This
from ORDERS_LOCAL
where TO_CHAR(ORDER_DATE, 'MM-DD-YYYY') between :P1_DATE_FROM and :P1_DATE_TO
should be
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P1_DATE_FROM,'MM-DD-YYYY') and TO_DATE(:P1_DATE_TO,'MM-DD-YYYY')
Reason: the column orders_local.order_date is of datatype DATE. If you convert it to a string using TO_CHAR then it will be a string comparison, not a date comparison.
Note that bind variables P1_DATE_FROM and P1_DATE_TO are strings - they're defined in the DOM on the html page and that has no concept of oracle datatypes so everything is just a string. If they're used as such in a date comparison, you're relying on implicit conversion by the database. It's safer to do explicit conversion using the TO_DATE function.
--UPDATE--
Your question starts with "I want the chart to show the amount of orders in a given date or range.". Well... there is your answer. The "Value" is the amount of orders on each day. Update your source query to include a count of the orders and group by day. Then make your value attribute the column that has the count.

PowerBi Dax - Create a Measure that ignores applied filters and display in barchart

In my data I have two columns of date - claim registration date and resolved date. My report is using resolved date as a slicer filter. I would like to build a bar chart showing registered claims by client segments. I have tried several approaches and functions but they all return single count value. What I want is actual counted values for each type.
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])),ALL(claims_data))
BySegmentRegistered = CALCULATE(COUNT(claims_data[client_id]),FILTER(ALL(claims_data),claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear]))))
I have tried above code and several other iterations but they all return single value across all client_segments. If I simply do COUNT(claims_data[client_id]) than it displays count by each segment but date is wrong, hence it doesnt work for me.
Any ideas?
EDIT:
I just tried this and it works.
BySegmentRegistered = CALCULATE(COUNT(claims_data[cliend_id]), claims_data[reg_date].[MonthNo] == MONTH(SELECTEDVALUE(DateTable[MonthYear])), REMOVEFILTERS(DateTable[MonthYear]))

Conditionally Filtering Out Rows based on 2 Parameters in w/ Power Query

I have a table similar to the one attached below:
What I would like to do, using power query, is conditionally filter out (remove) rows where CenterNum = 1101 and DepCode = 257. I figured Table.SelectRows() would work but it doesn't and the query just returns, this table is empty. The #"Expanded AccountLookup" ,in my formula below, is referencing the power query applied step before the one I am trying to create. I'm hoping to get some input on how to remove rows based on these two paramters.
= Table.SelectRows(#"Expanded AccountLookup", each [CostCenterNumber] = "1111001" and [NoteTypeCode] = "257")
Thank you!
You didn’t post a screenshot so it is hard to tell if the column format is text or numerical but try removing the quotes around the numbers
= Table.SelectRows(#"Expanded AccountLookup", each [CostCenterNumber] = 1111001 and [NoteTypeCode] = 257)
If that doesn't work, check the actual column names against what you are using, especially for case (upper/lower) and leading/trailing spaces. The best way to do that is to temporarily rename it, and look at the code for the "from name"

Show all rows as default in calendar in Oracle Apex

I'm creating a report table type calendar where users can create back up by date select a filter that would filter out the table values depending on the user selected. (i.e. if they choose user1, then only back ups with user1 will show up)
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
I'm having issues with trying to allow the user to see all the back ups of the table again (getting rid of the filtered value). My current query is this:
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
You can use case when statements in your query's where condition as follows:
select *
from my_table
where my_table.created_by =
(select user_name from my_table2 where app_users_id =
case :P106_BACKUP_BY_USER when 0 then app_users_id
else :P106_BACKUP_BY_USER
end)
And for getting better help, please paste your code as text not as an image next time.
This should work too:
...
WHERE b.active_server = s.server_id
AND (:P106_BACK_UP_BY_USER = 0 OR
UPPER(b.created_by) =
(SELECT UPPER(user_name)
FROM eba_bt_app_users
WHERE app_users_id = :P106_BACK_UP_BY_USER
)
);

Using SELECTEDVALUE in PowerBI

I have a table that contains the sample data from the attached image.
The sample table can be interpreted as follows: I have a list of customers with Customer_id, Customer_name and Email that have an account on 1 or more e-commerce sites. Every e-commerce site can be identified by the EcommerceSite_Id column.
If a customer has more than one account (eg: on EcommerceSite_Id = 111 and also on EcommerceSite_Id = 112) the GlobalClient_Id will have the same value (e.g. John has an account on the following EcommerceSite_Id: 111, 113 and 114. Therefore, he has the same GlobalClient_Id – “11” which is attributed based on some automatic criteria – in this example, email address).
What I want to achieve:
By using a slicer with the EcommerceSite_Id column, when selecting the EcommerceSite_Id 114, it should display all customers with a unique email address, that do not have an account in 114, by taking into account the GlobalClient_Id.
Therefore, the output should be
:
Therefore, as you can see I excluded the following customer_ids: 5 and 9. They do not have an account on 114, but I excluded them because they have the same ClientGlobal_Id with customers_ids 10 and 8, customers that have an account on 114.
I cannot find a solution. I tried to use selected values, but I don’t know if I am using it correctly.
Can you please give me an idea on how to solve it?
Welcome to SO. Here's one solution that might work for you:
Step 1. EcommerceSite_Id needs to be added to a separate table - it will contain distinct IDs:
Here's how the data model should look like:
Step 2. Create a measure
For each client, the measure will count the number of rows where a chosen EcommerceSite_Id appeared:
mExclude =
var EcommerceSite = SELECTEDVALUE(ES[EcommerceSite_Id])
var ThisCustomer = SELECTEDVALUE(CustomerData[Customer_name])
var Check = COUNTROWS(FILTER(ALL(CustomerData), CustomerData[Customer_name] = ThisCustomer && CustomerData[EcommerceSite_Id] = EcommerceSite))
return
Check + 0
When added to a table, and having a single EcommerceSite_Id selected (use your new table as a slicer), you get the following results:
Step 3. Finishing up
Finally, remove mExclude form the table and add it to the table filters. Set it up to filter values that are equal to zero.
The final result: