Qlik sense - Decile analysis with filter - qlikview

I am using below logic from https://community.qlik.com/t5/QlikView-App-Dev/Decile-analysis/td-p/1223944.
=Aggr(
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.1), 10,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.2), 9,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.3), 8,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.4), 7,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.5), 6,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.6), 5,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.7), 4,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.8), 3,
if(Sum(Profit) <= fractile(TOTAL Aggr(Sum(Profit), Customer), 0.9), 2, 1))))))))), Customer)
However , I want to create a filter to only show 10% or 20% or 30% customer. How can I create this filter.
After I create a filter pane by using this logic. When I select 10% it will continue the divide 10 part from the 10% of customer. The user can't identify they already select 10%.

Seems like all you'd need to do here is add a set expression like {1} to your Aggr() function so that the your expression isn't affected by user selections, including in the filter pane itself:
You can read more about the 1 Set Identifier on this Qlik Help page.

Related

Difference in SQL Date Query with Parenthesis

I inherited an a multiple Machine Learning processes that use essentially the same date query except for parenthesis. The following 3 date queries give a different number of rows. What exactly is the difference between each date query to give a different amount of rows for each?
1)
WHERE
((dbo.FACTINVOICEHEADER.PAID_DATE >= '2019-02-01'
AND dbo.FACTINVOICEHEADER.PAID_DATE <= '2020-01-31')
OR (dbo.FACTINVOICEHEADER.PAID_DATE >= '2018-02-01'
AND dbo.FACTINVOICEHEADER.PAID_DATE <= '2019-01-31'))
2)
WHERE
((dbo.FACTINVOICEHEADER.PAID_DATE >= '2018-02-01'
AND dbo.FACTINVOICEHEADER.PAID_DATE <='2020-01-31'))
3)
WHERE
dbo.FACTINVOICEHEADER.PAID_DATE >= '2018-02-01'
AND dbo.FACTINVOICEHEADER.PAID_DATE <= '2020-01-31'
The first query is selecting 24 months, minus one day (Jan 31st, 2019).
The second query is selecting 24 months.
The third query is equivalent to the second one.

Get "Week of 2nd" from Date field in power BI

I have a date field in my DimDate table.
I want to get another column WeekOf that would show the week number based on Monday.
For example I have date:
Date WeekOf
10/2/2017 Week of 2nd
10/9/2017 Week of 9th
10/16/2017 Week of 16th
Creating a new column with the following formula should give you what you want.
If you every want to change it to be the Week of a different day, change the 2 in the TargetDate variable to which ever day of the week you want.
WeekOf =
VAR TargetDate = DAY(DATEADD(Dates[Date], 2 - WEEKDAY(Dates[Date]), DAY))
VAR TargetDateText = CONCATENATE(TargetDate, SWITCH(TargetDate, 1, "st", 21, "st", 31, "st", 2, "nd", 22, "nd", 3, "rd", 23, "rd", "th"))
RETURN
CONCATENATE("Week of ", TargetDateText)

SQL converting number of days to weeks

I have a SQL table with a column that says number of days, and contains entries like 23, 26, 45, etc...
I am trying to convert each entry to a "week number". In essence, what I mean is that if my day entry is between 0 and 6, then, this is Week 1, if it is 7 and 13, then this is Week 2, 14 and 20, week 3, etc... Is there an "efficient" way to do this in SQL?
Thanks.
Thomas.
You need just the standard divide function. It ignores the remainder:
SELECT (Days / 7) + 1
You can try this and no need to add +1;
SELECT (Days / 7.00)

Access VBA Get Quarter From Month Number

I am stuck in trying to find the quarter of year number from the month number i.e. i have month number 2 which should be quarter number 1, how do i do this in Access VBA or an access query?
Thanks in advance.
You can use this function:
Public Function Quarter(ByVal MonthNumber As Long) As Long
If (MonthNumber < 1) Or (MonthNumber > 12) Then
Call Err.Raise(6) ' Value out of Bounds '
End If
Let Quarter = (MonthNumber - 1) \ 3 + 1
End Function
In Excel VBA I like using Choose as sometimes I need to get the financial quarter rather than the calendar quarter.
calendar_quarter = Choose(Month(Date), 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)
' if financial year starts in April - this will get the financial quarter from the current date
financial_quarter = Choose(Month(Date), 4, 4, 4, 1, 1, 1, 2, 2, 2, 3, 3, 3)
One liner for Excel:
=INT((MonthNo-1)/3 +1)
for SQL
floor(([MonthNo]-1)/3) +1

Get calendar week numbers in requested month in RoR

I've been searching for hours now and I just can't find the right answer.
Hope you can help me out.
Ruby: 1.9.3p194
Rails: 3.2.8
Goal:
1.9.3p194 :001 > get_weeknumbers_in_month 1, 2012
=> [1, 2, 3, 4]
1.9.3p194 :002 > get_weeknumbers_in_month 2, 2012
=> [5, 6, 7, 8]
1.9.3p194 :003 > get_weeknumbers_in_month 3, 2012
=> [9, 10, 11, 12, 13]
1.9.3p194 :004 > get_weeknumbers_in_month 4, 2012
=> [14, 15, 16, 17]
So, I actually want an array of calendar week numbers when the method get_weeknumbers_in_month is called.
Research:
To get the month numbers from a date:
DateTime.parse("2012-01-10").month
=> 1
To get the number of days in a month:
Time::days_in_month(1, 2012)
=> 31
To get the calendar week number of a date:
DateTime.parse("2012-04-12").strftime("%W").to_i
=> 15
Can someone please help me with this issue?
Thanks in advance.
If I understand, you've almost done!
the last is to calculate first and last dates for month, isn't it?
So something like next may work (not tested)
def get_weeknumbers_in_month(month, year)
first_week_num = Date.new(year,month,1).strftime("%U").to_i
last_week_num = Date.new(year,month,1).end_of_month.strftime("%U").to_i
(first_week_num..last_week_num).to_a
end