Stacked bar chart in Qlik Sense: one bar for one field - bar-chart

I have this table:
Survey1:
LOAD * inline [
Respondent, AnswerToQuestion1, AnswerToQuestion2
resp1, 1, 1
resp2, 1, 2
resp3, 2, 1
resp4, 2, 1
resp5, 2, 3
resp6, 2, 1
resp7, 2, 1
resp8, 3, 2
resp9, 3, 2
];
I want to get a 100% stacked bar chart from this data. But it is difficult both, in Excel and in Qlick Sense... These programs do not accept that I would want to summarise one field/column into one bar.
My desired result should look similar to this:
Is there a way to do so in Qlik Sense?

I think you want to alter the way the data is modelled using unpivot/crosstable - which would create a table more like:
Respondent, Question, Answer
resp1, Question1, 1
resp1, Question2, 1
resp2, Question1, 1
resp2, Question2, 2
You could then make a stacked bar chart with 2 dimensions - Question & Answer with count(Answer)/count(TOTAL<Respondent>Answer) as your measure to give you a percentage. Note: I haven't tested that code - I'd start with a table with those 2 dimensions and count(Answer) as a measure - then check that count(TOTAL<Respondent>Answer) gives the total number of answers you'd expect.
In the script editor, assuming your table is called "Answers" this could be done with something like:
Answers_new:
crosstable(Question,Answer,1)
Load * resident Answers;
drop table Answers;
rename table Answers_new to Answers;

Related

How to alternate rows after each 2 row background color in SSRS

I am trying to alternate every 2 rows background color from white to blue as per below design in SSRS:
I have tried the below expression but it does not give the expected result:
=IIf((RowNumber(NOTHING) Mod 4) < 3 , "Blue", "Transparent")
Has anyone ever done anything similar and is there a way to achieve this?
I've just tested the following and it works on a simple table. If it does not work for you, please share your table/matrix design including any row or column groups.
=IIF(((RowNumber(Nothing)-1) Mod 4) < 2 , "Blue", Nothing)
This simply offsets the mod calculation by 1 as the first row is 1 so we get a sequence of 0,1,2,3,0,1,2,3....
I find that adding a new column with the mod expression helps debug things like this. SO I would add a new column with =(RowNumber(Nothing)-1) Mod 4 as the expression and see what it returns.

SSRS Matrix header repeat on each page (but outside of group to show every header from ds?)

I have a Matrix which I am trying to get a specific header to repeat on each page. To keep it simple it looks something like this:
| | Months |
|Division| |
| Name | Sales |
--- new page for each division ---
If I include the [Month] columns inside the Division group, it only shows the [Months] that have activity for that [Division]. For each page (per [Division]) I want to show all active [Months] within the dataset, not just that particular [Division].
So I tried creating a new row above, OUTSIDE of the [Division] group. This worked great for the first page, but I cannot get it to repeat on each page.
Is there a way to somehow set a Matrix row as a header for each instance/page of that tablix in the report?
Or
Show every [Month] from the dataset, inside of the [Division] group, and not just the active [Months] inside the [Division]?
Hopefully that makes sense, if not I will try my hardest to explain better.
Thanks in advance!!
I found the answer here:
https://msdn.microsoft.com/en-us/library/dd207045.aspx
Under "To Display a static row or column on multiple pages"
Thanks

SSRS Get table last value from previous page

In Reporting Services imagine that i have a table with 1 column, that when is printed (2 pages) looks like this:
1st Page
Value
1
2
3
2nd Page
Value
4
5
6
What I need is that when it is printed looks like this:
1st Page
Value
1
2
3
2nd Page
Value
Last Value From Page 1: 3
4
5
6
Briefly what i want is that,in each page of the report (except in page 1) the first value is the last value from previous page...
Is that possible?
Thanks in advance...
There is built-in functionality to display row and column headers on multiple pages. This also tells you how to keep a static row or column visible while scrolling. Note the KeepWithGroup and RepeatOnNewPage properties.
If the rows you would like to repeat across pages are not group headers, you may have to make your own page group. This approach is not very pretty, but you could structure the data with flags to signal its own page breaks, and then manually include a repeat row after the page break. So the data set would look like:
Value PageFlag
1 1
2 1
3 1
3 2
4 2
5 2
6 2
You would add a grouping on PageFlag with a page break for each group.
On the Page Breaks tab, select Between each instance of a
group to add a page break between each instance of a group in the
table.
There is more detail on the KeepTogether property here. You can also read up on Pagination and Page Layout.

Drawing a bar chart, but with some restriction

I want to draw a chart in linux like this:
1################# 64.85
2################### 72.84
3####################### 91.19
4####################### 91.61
5########################### 108.66
6############################ 110.69
7###################################### 149.85
8####################################### 156.60
9########################################### 169.81
I want to do that in python, of course you noticed that I don't want code like:
for i in data:
print "#"*i
because data may contain big numbers, so it is not nice to print "#" milion times.
So what is the mathematical equation that I must use to do this, I think this is a kind of mathematical problem
Thanks a lot
You have to work with percentages I think sum up all you values and then you do bar value / total of bar values
So if I have the following values 1 2 3 6 the total will be 12 so then
i will do 1 / 12 the percentage will be 8 so you print '#' 8 times and so on.
then the max # you can print is hundred.
I don't know if this is what you want, but hope this will help.

SSRS - How to build a simple multi-column report?

I am using SQL Server 2008 and I want to show 1 single field from a table in multiple columns in the report. Just like if I were to print labels. How can I achieve this?
Example:
Instead of printing:
Names Report
Andrea
Austin
Barbara
Bob
Bruno
Cathy
Chis
...
I want to print in columns (say 3 fixed columns):
Names Report
Andrea ---- Bruno ---- Darren
Austin ---- Cathy ---- Francis
Barbara ---- Chis ---- Gabriel
Bob ---- David ---- Gerald
....... ---- ....... ---- .......
Edit: If I run the report and click on "Print Layout" button, I can see multiple columns. Can I set this mode as default?
For Horizontal layout of labels...
One choice is to use the columns property on the report or body elements.
This doesn't always display correctly On reportviewer. I've noticed that even if it displays correctly on your IDE and when you export to PDF. In the report viewer it will display only one column. Also it snakes the labels top to bottom then left to right.
One choice is to use a matrix and group on every 3 rows (if you want 3 columns).
This one is a little complicated.
My solution of choice is to put 3 vertical lists on the page. put the same label in each list. Return the row number in your dataset. Then just filter each list on modulo 3
For example
Result set
RIndex Fname
1 abe
2 burt
3 fred
4 george
Filter expressions
list 1 -> =Fields!RIndex.Value mod 3 = =1
list 2 -> =Fields!RIndex.Value mod 3 = =2
list 3 -> =Fields!RIndex.Value mod 3 = =0
Result
Abe Burt Fred
George
The method I use is a bit similar as what Vern suggested but differs enough to make it worth mentioning here.
You can combine the ROW_NUMBER with the modulo (%) operator directly in the query to fabricate the column number in which the record should get displayed. Here's an example that generates one while taking a group into account:
declare #numberOfColumns int = 4;
select dpc.EnglishProductCategoryName, dp.ProductAlternateKey
, (ROW_NUMBER() OVER (
PARTITION BY dpc.EnglishProductCategoryName
ORDER BY dp.ProductAlternateKey) + #numberOfColumns - 1) % #numberOfColumns + 1
as DisplayColumn
from dbo.DimProduct dp
inner join dbo.DimProductSubcategory dps on dps.ProductSubcategoryKey = dp.ProductSubcategoryKey
inner join dbo.DimProductCategory dpc on dpc.ProductCategoryKey = dps.ProductCategoryKey;
To get this displayed I'm using nested tables which are then filtered on DisplayColumn.
Have a read through following article for all the details: Creating Multiple-Column Reports
Use the 'Report' menu in Visual Studio and select 'Report Properties'. You can set columns in the 'Layout' tab.
Try this msdn article about newsletter-style reports for more details: http://msdn.microsoft.com/en-us/library/ms159107.aspx
This method does have a limitation though so in some cases it might not be applicable:
Only PDF and Image renderers support
newsletter-style reports.
EDIT:
So one approach is to use multiple tablix with a filter that checks RowNumber and accordingly displays particular records in each table.
The other way is called Newsletter-style report (link). This formatting is retained only when report is exported as PDF or Image. It can be previewed only when you select 'Print Layout' on the Preview tab in Visual Studio. Here is an example:
Create a new report with the foll. dataset: SELECT ID,NAME FROM TABLENAME
Add a new table to the report and select the ID and Name as columns
Click on the tablix and press F4 to edit the tablix properties. In the properties window, change the Size - set the width to 2in
Click on the report area outside the report page boundary and press F4 to edit the report properties. In the properties window, change the Column value to 3, and column spacing value to 0.1
On the report scroll to the right hand side, you will notice that there are 2 new columns (so totally 3 columns on the report - because you selected 3 in step 4 above). Now click on the margin at the start of the column 2 and pull it further to the left to bring it as close to the column 1. This is only to reduce the need for huge page size.
Right click on the report area outside the report page boundary and select Report Properties. Change the Page Size - Set the width to 10in
Preview the report. Now select the 'Print Layout' tab to see the result. This formatting is retained only when report is exported as PDF or Image.
As noted in points 5 and 6 - since the report body flows into multiple columns, you must ensure that the page size is at-least equal to -> ([Original report body size times the number of columns] + all the column spacing values). Otherwise it will look messy.