SQL expression for when .... then ....does not work properly - sql

I am kind of new to qgis and this forum but I have a problem for which i would like some help. I made a raster layer indicating different landcovers based on an image. I now want to assign the most frequently found landcover within a polygon to be assigned to that polygon. I intended to do this by counting the landcover pixels within the polygons and then making a new field in the attribute table from to polygon to assign the highest count of pixels to the field. i intended to do this using a when ... then ... expression. However, this is not going right, it first of all does not assign a value to all the records, so some get a 'null' value. Also in some situation it actually does not assign the highest count to the new field.
raster and polygon field
Expression part 1
Expression part 2
Result from the expression in attribute table
As can be seen in this figure, landuse3 has 'null' values and the highlighted record is also incorrect, the result should be 'road' instead of 'flat roof'.
It would be really nice if someone could help me out with this :)

Related

MDX - Display the labels/values for dimensions for this MDX query

Usually I display a value for dimensions by using the CurrentMember.Value/caption as as an alias.
For the following query this breaks with an error along the lines of
'The hierarchy [Measures] appears in more than one axis or in an axis/axes and a slicer too'.
Which I understand.
So how do I edit/expand the query such that I see the book values on rows (normally achieved with
'WITH Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION'
and the column dimension values along the top?
(Excel image below, values white color'd out as on client site.)
SELECT
NON EMPTY ([Ccy].[Ccy].[Ccy])
ON COLUMNS ,
NON EMPTY
([Book].[Book].[Book])
ON ROWS
FROM [TraderCube]
WHERE
([Date].[Date].[ALL].[AllMember].[2019-12-12],[Measures].[JTD.SUM])
I have made more progress however this comes out staggered duplicating the row / book label at each repeated currency.
Does anyone know how I would:
1) Get the currencies along the top?
2) Have one row / book label per row?
WITH
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY (HIERARCHIZE(([Ccy].[Ccy].Members, {[Measures].[Book_Label],[Measures].[JTD.SUM]}), POST))
ON COLUMNS,
NON EMPTY (HIERARCHIZE([Book].[Book].Members, POST))
ON ROWS
FROM[TraderCube] WHERE ([Date].[Date].[2019-12-13])"
As an update for anyone who comes across this thread/question, for me I am writing a C# layer that translates simple user words and constructs MDX. I query the remote cube and then I return a 2D array. Up until now I constructed the headerRow etc myself and I returned the row dimension labels using the MDX itself.
I have now discovered that metadata is available on the AdomoClient libraries I am using.
This tutorial has inspired me:
https://www.codeproject.com/Articles/28290/Microsoft-Analysis-Services-2005-Displaying-a-grid
It's not a direct answer to my query of getting all of the labels in MDX but it will mean I can construct my headerRow (may be more than one row as seen in Excel pivots) and populate my row labels differently using the positions property of each Axes on the set (Axes[0] is columns, Axes[1] is rows) and the Positions property has a member property too.

Expression chart colors depending on the dimension for no selected values

I was planning to do a Straight Table chart like this:
The four dimensions should always appear and have exactly the same colors (the only variation is the expression values).
What I have now is the dimensions and the values as I want except for the colors. The initial data is organized in a table like:
Project Status
1 Completed
2 On Track
3 On Track
4 Deviating
So the #RA variation is the percentage of each status value from the total. However, it can happen that in some cases one status value is 0. And I get this:
The condition for the colors is set in the color background expression, like this:
I also have to say that as some fields of the dimension have no values they disapear, so they are forced to appear using the Show All Values in the dimension tab.
Any one knows how to make the colors always fixed for its dimension even when the value is null?
Thanks for the attention

Make Spotfire ignore empty values in the categories of charts and show a visualization without "spaces" between the bars

I have a group of trellis graphs on some data, in there you can see a numeric variable on the Y axis and a series of cell dishes on the X axis. Not all the numeric values are present on all the series of cells. Because of this the visualization results in a graph with empty spaces:
This is OK most of the time but the thing is I would like to avoid the "empty spaces, only in these graph series, that you can see between the bars. I would like to see showing only the pattern of the cell dishes where I have data.
Trying to do so I tried creating a calculated column to use it as a ordering index (https://docs.tibco.com/pub/sfire-bauthor/7.9.0/doc/html/en-US/GUID-8CAA18D0-CF28-4707-9945-041BDFD99E99.html) (Sorting Filter values asc/desc on Tibco Spotfire), after that "Limit data by expression" using a "[MyColumn] is not null" on it (https://community.tibco.com/questions/can-i-automatically-make-spotfire-ignore-empty-values-categories-charts) (How to show the top 10 column values in Spotfire) with no luck and I tried also (https://docs.tibco.com/pub/spotfire/6.5.1/doc/html/ncfe/ncfe_details_on_custom_expression.htm) create a custom expression, which I think it would be a good solution because I understand it will only affect these graphs and not the complete set of visualizations but no, I don't reach the point to change it. Last that it should work but it doesn't is to "Show/Hide Items" under a Boolean expression that it would include that "[Axis.Value] is not NULL" and "Apply individually for each trellis panel" of the numeric column which sound terrific but... nope, it didn't work either...
Any help would be appreciated, now I will select one by one on individual graphs extracting them and plotting them in other place but this is not very useful as a "large scale" solution. I am sure there is a way to insert a proper expression to avoid the null values of the cross of both variables, the numeric and the cell dishes.
this is because you are trellising data, not the axis. you won't be able to filter out values on the x axis; it's simply not how trellis works.
using multiple visualizations is the solution, but I assume you've got n sets of categories that you want to separate out without creating a ton of charts on the page and perhaps you can't guarantee the number of categories or their names, so you want to build a flexible solution.
please check out an answer I just wrote over here which illustrates how to use a document property and a property control to limit a visualization. your property control can be linked to automatically and dynamically display unique values in your "category" column (the one you are trellising by). maybe this can be a solution for you?

Reporting Services - Two filters on the same chart Category Group?

I have sales data that I'd like to plot on my chart. However, at a specific point in time, we had a change taking place I'd like to ensure is clearly visible in the chart, preferably by dividing the sales data (which is stored in a single SQL Server column) into two different chunks, which would allow me to then treat them as different data series.
I used to solve this in Excel by storing the post-event data in a different column (by simply dragging them to a different column), and thus I was able to treat them as a different series (the blue and green line in the chart below. The red and orange line are pre-event and post-event averages):
I'd like to reproduce this effect in SSRS, but am not sure how to tackle it. I've tried using an approach where I added two category groups, both pointing to the date-time column, and applying filters to them (one <= the cutoff date, the other >=).
I then added my sales data twice, with the idea I could somehow connect them to the individual category groups, but that does not seem possible.
Has anyone tried anything like this before, or would have a different approach to achieve what I'm trying to get?
Thanks!
I managed to get this to work, and figured I'd share how to do it.
My dataset contains a field called DATEKEY, which stores the date in the format YYYYMMDD. It's possible to use this in an expression and evaluate the date for a specific row. In case the expression evaluates to true, we display the value. If not, we display a blank string.
In case we want to show the values prior to the date, the expression would be:
=IIF(Fields!DATEKEY.Value <= 20130601, Avg(Fields!My_NUMBER.Value), "")
The second series can then be made by reversing the symbol:
=IIF(Fields!DATEKEY.Value >= 20130601, Avg(Fields!My_NUMBER.Value), "")
The graph then looks like this:

Qlikview Expression to get Average in comparison to selected criteria for Chart

I am trying to create a chart that displays the average of a parameter of an entire category. The problem is that in sheet 1,2,3,4, etc, the charts I have reflect one parameter, so when I go to compare this parameter to the average in my new sheet, I only get the average of the fields that have been selected in prior sheets. I want it so that I can create a new chart with one bar as an average of the entire population, and another bar in the same chart that depicts the average of the selected parameter(s). Ideally, I would have two dimensions/x axis categories, one for the selected criteria, and one for average of all categories. Can someone help?
Thanks.
I believe the way to handle this is with set analysis. You can create one expression with the normal avg(parameter) and another expression with some embedded set analysis. See example below.
Expression1: avg(parameter) // will agregate everything in the current selection
Expression2: avg({1<category='YourCategory'>}parameter) // will aggregate everything in a category that you set in the set analysis syntax.
With some more specific info I would be able to get you an actual expression, but hopefully this helps.
EDIT
Updated to reflect new information provided in the comments.
Expression1: avg(parameter)
Expression2: avg({1}parameter)
In set analysis syntax the {1} means the entire universe of data where as {$} is your current selection. In other words, 1 is your data with nothing selected. In my first example above, the {1<category='YourCategory'>} statement uses a modifier signified by the <> so that you would be performing the aggregation over the entire universe with only the value specified in YourCategory selected.
So if the scenario is that you have currently selected let's say, 5 zip codes, your current selection ({$}) would be those 5 zip codes and the entire universe ({1}) will be as if you selected no zip codes. Therefore comparing those two populations side-by-side in two Expressions should give you the comparison you want.
Caveat: Using the {1} syntax in your expression means that your average of "all zip codes" will always be the average with nothing selected unless you put something in the modifier as in my first example. See this more detailed explanation.