How to dynamically Change Column name(column header) with filter in Qlik Sense - dynamic

I have a Filter in my dashboard as Financial Year. In that filter there are currently two years. 2021 and 2022 however as data is loaded there will be 2023 also so I want column name RANK to change dynamically to the year I select from filter pane. For eg. If year 2022 is selected from filter pane it should show RANK 2022. Please anyone help me with this
COMPANY NAME RANK 2022
A 21
B 4
C 7
Title should change dynamically
If year 2022 is selected
COMPANY NAME RANK 2022
A 21
B 4
C 7
if year 2023 is selected
COMPANY NAME RANK 2022
A 21
B 4
C 7

If I'm understanding correctly, you could try one of these options by updating the Label property for your [Rank] field:
Only() function
='Rank ' & Only([Financial Year])
This uses the Only() function to display the currently possible [Financial Year] only if one year is possible. That means that if you select multiple years, the [Rank] values will still filter correctly to those selected years but the column name will not display the years since it will return a value if there is only one unique value to return. Note that this is an aggregation function so it's not strictly based on what's selected. If your data model changed such that there was only one [Financial Year] value loaded, the header would display that year even if you weren't actually selecting it. That's why I use the term "possible" instead of "selected."
Concat() function
='Rank ' & Concat(distinct [Financial Year], ', ')
This will make the header display all distinct, possible years as a comma-separated list. This means if you have multiple possible or selected years, they'll all be shown in the header. Just like the Only() function, this is an aggregation, so it's not strictly based on selections.
GetFieldSelections() function
='Rank ' & GetFieldSelections([Financial Year], ', ')
This function works similarly to the Concat() function, except that it is not based on possible values but instead based strictly on selected values.
if(), GetFieldSelections(), and GetSelectedCount() functions
='Rank ' &
if( GetSelectedCount([Financial Year]) > 1, 'Multiple Years',
if( GetSelectedCount([Financial Year]) = 1, GetFieldSelections([Financial Year])))
This uses an if() statement to see how many years are selected. If more than one year is selected, it will display the text "Multiple Years." If only one year is selected, it will display that year. If no years are selected, it will not display anything.

Related

Conditional styles on a calculated value in Cognos

I have a report (Pivot table) for which I have a value everyday. My goal is to calculate the variance every day and highlight with conditional styles.
1 jan. 23
2 jan. 23
3 jan. 23
5
25
42
I have a query who calculates the variance between days in % (which I dont want to put in the report).
My conditional style rule is [Table].[Pourcentage variation D-1] between 0,05 and 10.
Since my request is not in displayed my report, I have this error :
RSV-VAL-0032 The following expression is not valid. If the item exists
in a query but is not referenced in the layout, add it to a property
list.
The problem is that I don't have the "Proprety list" in my pivot table like in can have in a Data table.
How can I highlight my variance based on a request that I dont display in my Pivot table ?
Thanks for helping
Add the calculated field to the pivot table (I know you do not want this in the layout, this is just to test if that removes the error). See if the conditional style works the way you expect.
If so, change the column for the percentage data item to property, set box type to none. This way it is still something that can be referred to, but is hidden from the final result

VBA: Count unique values that meet two criteria

I have three columns: ID, events, and month. I need to get the count of events by month unique by ID.
So far I have the count of events by month (e.g. 1806 unique logins in May) using CountIfs(Range("B2:B276609"), EventName, Range(C2:C76602"), m)).
How do I filter this above count so only the unique IDs within that count is being used? Note that I have to loop this through a bunch of event types and months.
To make this clearer, let me provide some sample data:
ID Event Month
1 Login May 16
2 click July 16
1 Save June 16
1 Login May 16
3 Save June 16
From this I need to get the following info:
1 unique login in May 16
2 unique saves in June 16
1 unique click in July 16
You can use Excel's inbuilt remove duplicates function.
ActiveSheet.Range("A2:C76602").RemoveDuplicates Columns:=Array(1,2), Header:=xlYes
Based on the link in Ralph's comments which can be found here here you get:
To know how many unique items you have you can use this regular formula:
=SUM(IF(FREQUENCY(COUNTIF(Colors,"<"&Colors),COUNTIF(Colors,"<"&Colors)),1))
I then extended this to multiple columns just change the countif formulas to countifs. (different ranges used obviously).
=SUM(IF(FREQUENCY(COUNTIFS($A$1:$A$10,"<"&$A$1:$A$10,$B$1:$B$10,"<"&$B$1:$B$10),COUNTIFS($A$1:$A$10,"<"&$A$1:$A$10,$B$1:$B$10,"<"&$B$1:$B$10)),1))

Variance column in QlikView

I need to create a "Variance" column in qlikview:
2013 2014 Variance
Measure 1 100 110 10%
Measure 2 105 100 -4.8%
...
Can this be done in Qlikview with just one "Calculated dimension" column that says something like:
[Value for Column2]/[Value for Column 1] - 1
So that it works for any new measures I add in the table and regardless of what the column 1 and column 2 are?
EDIT:
Sample Data:
Year Measure1 Measure2
2012 9750 197
2013 10000 200
2014 11000 210
2015 11500 215
I need the output to be structured as shown below with the Variance column as a calculation between 2 selected Year dimension values.
You can do this with the Column() function.
Column(2) / Column(1)
The number refers to the Expression column -- first Expression is #1, etc. Dimension columns are not counted.
An alternative that is insensitive to column postion, you can use column labels in the expression. Assume expressions with labels of "Sales" & "Margin". The variance expression can be written as:
[Margin] / [Sales]
I am 99% certain there is no built in function to do it.
I've played with a few options I thought might work, but only this is proving of any use.
I've defined the 2 calculated dimensions as variables Year1 and Year2 which I change through an input box. Then the simple calculated dimension =[$(Year2)]-[$(Year1)] gives me a new dimension of the variances.
This assumes the Measure is something that comes from the data, something like this, and now you just want to display it over varying years. I haven't considered what to do if the measures are all expressions.
Here is how to do it using variables and expressions. This will create 2 new columns that will look like a new dimension but will actually be defined by the use of an if() statement.
First step in the script we need to create a dimension that has the Measures in it. this should not associate to any of the column already in the data. (UDR stands for User Defined Report). the dual just allows us to define a sort order that is not alphabetical.
UDR:
load dual(UDR,Sort) as Rows inline [
UDR, Sort
Measure1, 1
Measure2, 2];
the result should be something like this.
Next step is creating the 2 variables for the years.
I do this in the script, but you could use any method of variable creation.
set vMaxYear="=max(Year)";
set vMinYear="=min(Year)";
Now we use the field Rows as the dimension.
And we need to create an expression for the max selected year. Notice that the first if() is testing which rows of the UDR the expression is on and then the definition of the expression for that line is provided. The second if() is testing the year dimension against the variable vMaxYear which will change as selections are made. Min year is the same just replace vMaxYear with vMinYear.
if(Rows='Measure1',sum(if(Year=vMaxYear,Measure1)),
if(Rows='Measure2',sum(if(Year=vMaxYear,Measure2))))
Lastly we use the column() function to calculate the variance in the third expression.
column(1)/column(2)
To make the expression labels dynamic I simply add =vMinYear into the label.
The result is this table, that will respond to my selections in the year list box.
2013 vs 2014
2014 vs 2015

How to filter information within a Cross Tab in Crystal Reports

I am trying to create a single cross tab that includes both filtered and non-filtered data. I understand that I could do this by creating separate cross tabs in separate groups, then using filter expert on the group level, but I need the results to displayed in the same cross tab. I believe a similar solution to this might work, but am unclear on the implementation:
Crystal Reports Cross-Tab Column Totals as Variables
I am attempting to report on the frequency of known customers and walk-in customers (given a set customer number).
I have created a report with a cross tab with the following values:
Rows: AR_CUST.STR_ID (gives store number)
Columns: PS_TKT_HIST_DAT (gives purchase date)
Summarized Fields:
DistinctCount of AR_CUST.CUST_NO (gives count of unique customer numbers)
DistinctCount of PS_TKT_HIST.TKT_NO (gives count of tickets)
Embedded Summary (gives ratio of unique customers to number of tickets)
This works exactly as it should.
We have one value of AR_CUST.CUST_NO that is used for walk-in customers (we don't retain customer information for purchases using this customer number). So I want to calculate two additional cross tabs with the same information. The first would exclude all entries in PS_TKT_HIST.TKT_NO when PS_TKT_HIST.CUST_NO equals *WI (that's not a wildcard, that's the exact entry in SQL). The second wouldn't exclude *WI records, but would count each instance of a ticket under the *WI customer number as a separate customer. To clarify that, in the second report, my embedded summary in the cross tab would be:
DISTINCT_COUNT of CUST_NO when CUST_NO <> *WI +
COUNT of CUST_NO when CUST_NO = *WI
Is this possible by recording embedded summary values from the three cross tabs as variables, and then inserting those variables into a fourth crosstab?
Thanks
Tyler
I don't think you can extract the embeeded summary from 3 cross tabs and insert in 4th cross tab. May be I don't know.....
But I can suggest you one work around for this.
Since you have 3 cross tabs...
Take 3 sub reports in the main report and implement the individual cross tab in the 3 sub reports..
Implement the cross tab not by using the cross tab but by placing the recurring fields in the detail section and summary in the footer section and divide the detail sections using lines.. and make the report as exactly as cross tab.
Row Column1 | Column2 | Column3 //Group Header as cross tab columns
-------------------------------------
1 10 | 10 | 10 //Detail Section as cross tab rows
2 20 | 20 | 20 //Detail section as cross tab rows
-------------------------------------- // Lines will be line objects in crosstab
30 | 30 | 30 //Group Footer as cross tab summary
Above design will give your out exactly as corss tab.
Now from 3 sub reports take the required values using the Shared Varialbes and perform your calcultion in main subreport or another sub report as per your requirement.
For eg in subreport create like this:
Shared NumberVar x;
X:=DISTINCT_COUNT of CUST_NO when CUST_NO <> *WI +
COUNT of CUST_NO when CUST_NO = *WI
In main report
Shared NumberVar x;
x
Perform same in all sub reports.
This approach will give you cross tab output at the same time you can manuplate the calculations.
Let me know how it goes

ms sql Query for POS item sales

I have a SQL question regarding POS system item sales data. In the database, there is a "Totals" table. In that table, contains various records identified by the "TtlType" field. I'm working with 2 types. Values 11, which is the Item POS Sales, and 12, which is the Item Cost Sales.
When I do my SQL Query, i'm doing something along the lines of
SELECT ItemNumber,
SUM(ItemCount),
SUM(ItemAmount)
FROM Totals
WHERE TtlType = 11
AND Date = 8/1/2012
etc.
I'd like to also include TtlType 12. How can I merge all of the data into one row?
If I change my WHERE to include TtlType 11 & 12, I get 2 seperate rows for each menu item. The first one being TtlType 11 which is the Sell Price, and the next being 12 which is the cost. BOTH TtlType use the SAME field names to record information (ItemCount, ItemAmount)
I hope i explained this well enough. When I use the GROUP BY, I still get the same results.
I'm not sure I understand your data structure fully, or the significance of ItemNumber.
However, you don't need a GROUP BY to do SUM as you already know, but including ItemNumber in your SELECT & GROUP BY will definitely cause you to have duplicate rows as it will be grouped on that column.
You shouldn't have any issues with the two SUM functions with just
SELECT SUM(ItemCount), SUM(ItemAmount) FROM Totals WHERE TtlType IN (11,12)
AND Date = 8/1/2012