Apex Chart - inapropriate sorting - bar-chart

Below the chart which causes problems
There are hundreds of items . Every day each item appears a several times. My idea was
to show only items which appears most frequent (at least MIN.PERCENTAGE value)
sum all other items which appears less than value of MIN.PERCENTAGE
and add them as "Others".
When you look at bar from 2022-07-11 data are displayed correctly. All others (next) bars are also OK but Item which not exists 11th appears always on top of bar. And sorting does not work anymore :( It seems that sorting is always as in the first bar.
Below the data I use
And mapping from chart settings:
SERIES NAME: ITEM
LABEL: DATE
VALUE: COUNT
Any finally the sql query :
select date
, item
, count
, rank
from source
where OK is not null // ok means percentage >= P10_PERCENT
union all
select date
, 'others'
, sum(count)
, 999
from source
where ok is null /// sum all items with percentage < P10_PERCENT
group by date
order by 1 , 4 desc
Why only the first bar is sorted correctly?
Why "new" items appears always on top of the bar. How to force sorting every bar according to data from query ?
Any ideas ? Any help ?

Related

Show new rows per day in Grafana from MySQL table

I have a fresh Grafana setup which is connected to a single MySQL data source. I'm trying to create a simple Bar Gauge which has vertical bars, one for each of the last 10 days where the values is the total number of rows added on that day, based on the "created" column.
My table is simple...
id, int
created, datetime
name, string
I have the following query which I've built using the Query Builder...
SELECT
$__timeGroupAlias(created,1d,0),
max(id) AS "Brands"
FROM brands
WHERE
created >= CURDATE() - INTERVAL 30 DAY
GROUP BY 1
ORDER BY $__timeGroup(created,1d,0)
Works great however, it's showing the total number of rows i.e. the count is increasing each time. It should instead only show the number of rows created on that day.
01|03|05|08|12
| | | |==
| | |==|==
|==|==|==|==
==|==|==|==|==
It's worth mentioning that I've got the "Format as" set to "Table". If I set it to "Time Series" then my chart goes blank and has no bars at all.
And secondly, the labels beneath the bars all say "Brands" - I'd like to replace this with the date.
Any help would be greatly appreciated!

How to fix the error dividing by zero in my expression in visual studio reports?

I created report in visual studio.The problem is with dividing by zero in total fields.
I have one column with value 00:03:15 and another column with 00:00:00
I want to sum these columns and want to show me average value from first and second column.
I used this expression ( formula ) in my case :
=Format(
TimeSerial(0,0,
Round(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/count(Fields!PRESENTATION_NAME.Value))
, "HH:mm:ss")
I used this https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/ and looks like :
=Format(
TimeSerial(0,0,
Round(
iif(count(Fields!PRESENTATION_NAME.Value)=0,0,
(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/iif(count(Fields!PRESENTATION_NAME.Value)=0,1,count(Fields!PRESENTATION_NAME.Value)) ) ) )
, "HH:mm:ss")
But shows me an ERROR.Anyone who know how to fix that?
Your data is something like below, Correct me if I am wrong. At the Bottom I have added Total for both columns.
Note: You will have to take care of what type your column (T_INBOUND and N_INBOUND) return values.
Now to create a Total for T_INBOUND and N_INBOUND
To add totals for a column group In the tablix data region row group
area, right-click a cell in the column group area for which you want
totals, then point to Add Total, and click Before or After.
A new column outside the current group is added to the data region,
and then a default total is added for each numeric field in the
column.
Link:
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-a-total-to-a-group-or-tablix-data-region-report-builder-and-ssrs?view=sql-server-2017
Once you have Total you can create create a Cell Either next to your Total or below Total and add expression as below
IIF(IsNothing(Fields!Total_N_BOUND.Value) OR Fields!Total_N_BOUND.Value=0,0,
Fields!Total_T_BOUND.Value/Fields!Total_N_BOUND.Value)

SSRS - Sum Last 12 items

I have a Total column and am summing all the values in the row with:
=Sum(Fields!MyField.Value)
How can I sum only the last 12 items?
This is valid:
=Last(Fields!MyField.Value)
I need something like the below...
=Sum( LastX(Fields!MyField.Value, 12) )
You could achieve this result by creating a subquery in your main dataset query. You will just have to have a value that you want to sort on in descending order.
Say you have a table sorted by the price in ASC order. You want to sum the last 12. You just need to flip the sort in the subquery and sum the top 12.
SELECT OtherFields, (SELECT TOP 12 Sum(S1.MyField) FROM MyTable S1 ORDER BY S1.MyField DESC) AS BottomTwelveSum
FROM MyMainQueryTable
Yes this value will repeat in your dataset, however if you place it correctly in the Table you should be fine, just dont show the value in the details section. This wont add additional rows. Another solution would be using a subreport, however this is much quicker on render time.

How to show all legend keys for 0 or null value results, in SSRS?

I'm trying to build a bar chart that displays Events per Year. Each year divided into 4 quarters.
The problem arises in case that one, or more, quarter doesn't have any events in any year. In this case the legend key for this quarter doesn't appear.
For example, if no events took place in 1st quarter, then the legend show keys for 2nd, 3rd and 4th quarters only.
I need to make the legend always shows all keys, even if one, or more, doesn't have any values.
How can I accomplish this??
A similar question is here but the answer doesn't solve the problem.
Any help is appreciated.
Applying #alejandro answer, I get this result.
The missing quarter, Quarter 3, is renamed to Series1 and located at the first place. Any suggestions?
There is no way to build the legends and labels based on data that is not present in your fields.
You can create a table or a CTE with all quarters, then use LEFT JOIN operator to relate each row in your data with the corresponding quarter, if a quarter doesn't match any row in your data it will return null for each column in your data but will include the quarter, which lets SSRS build the legend.
WITH quarters
AS (SELECT 1 [Quarter]
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4)
SELECT a.[quarter],
b.*
FROM quarters a
LEFT JOIN YourDataTable b
ON a.[quarter] = b.[quarter]
After that you can use Quarter field in your Chart and it will show all quarters in the legend even if there is no data in one or more quarters.
Let me know if this helps.

SSRS Line Chart X-Axis group by Month

everyone. For the life of me I cannot figure out why the X-Axis is pulling 2 dates in each month when I want it to group by each month. In the Values I have:
Value Field =RunningValue(Fields!new_actualsalesfromsplit.Value, Sum, "Chart1_SeriesGroup")
Category Field: =Fields!closedate.Value
Category Groups =Month(Fields!closedate.Value)
Group On =Month(Fields!closedate.Value)
Series Group by ["salesperson']
The chart should have a line for each sales person, and each month should be a cumulative representation of the sales by that person. Thanks for any help.
Set the category field to "=Month(Fields!closedate.Value)", or something similar that will net the results you need. Right now, even though you're grouping by month, you're still telling SSRS to use the atomic data for your X axis, so that's what it's doing.
It may make your task simpler to just add a Calculated Field to your dataset - open the dataset properties window, go to the fields tab, and click "add". Set that field to your month value, use it for grouping and your X axis.