Qlikview Format textbox expression as percentage to 3 decimal places - textbox

I am trying to show percentage increase / decrease based on week number for 2018 v 2019 with an expression in a textbox in Qlikview: Here is my expression:
= num(Sum({<Year = {$(=Max(Year))},
Week = {"$(=Week(Today()))"}>}Retail) - Sum({<Year = {$(=Max(Year)-1)},
Week = {"$(=Week(Today()))"}>}Retail)) / num(Sum({<Year = {$(=Max(Year)-1)},
Week = {"$(=Week(Today()))"}>}Retail),'##0 %')
No matter what i try i end up with -0.38877082 etc.
What am i doing wrong?

Please fix parenthesis and formatting:
= num(Sum({}Retail) - Sum({}Retail) / Sum({}Retail),'##,#0.00 %')

Related

Calculating Age in X++

I am trying to calculate an age in x++ where the customer is born on 1/6/2010 to the selected day of his visit - 1/6/2023 today but the result doesn't give me 13 years old but gives me 12.
real ageDiffReal;
int ageDiffInt;
date datetoday = DateTimeUtil::date(Visitas.RFC_DataVisita);
ageDiffReal = (datetoday - mkDate(dir.BirthDay,dir.BirthMonth,dir.BirthYear)) / 365.242199;
ageDiffInt = Round(ageDiffReal,0);
info(strFmt('%1,%2',ageDiffReal, ageDiffInt));
I tried with / 365 and with 365.25 because of leap years but still didn't work well
You're using round(...) incorrectly.
ageDiffInt = decRound(ageDiffReal, 0); // Better
ageDiffInt = round(ageDiffReal, 1); // Works too
round(...) - The number that is a multiple of the value specified by the _decimals parameter and is closest to the value specified by the _arg parameter.
See https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-math-run-time-functions

How to plot Higher time frame indicator using end-of-day value of Lower time frame indicator ? [Pine Script] /[Tradingview]

I have written a script (Pine script / Tradingview) like this :
//#version=5
indicator("Normalized (ATR - wise) Relative strength of a stock compared to an index (daily close comparison)", "Normalized (ATR - wise) Relative strength of a stock",precision = 2)
//Input
comparativeTickerId = input.symbol("VNINDEX",title = "Comparative Symbol" )
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
lengthFastMA = input.int(5,minval=1, title="Fast MA")
lengthSlowMA = input.int(25,minval=1, title="Slow MA")
//Calculation
baseSymbol = request.security(syminfo.tickerid, "60", close)
fixSymbolBar = request.security(syminfo.tickerid, "D", close[1],barmerge.gaps_off, barmerge.lookahead_on)
atr_baseSymbol = request.security(syminfo.tickerid, "60", ta.atr(25))
normalizeSymbolBar = (baseSymbol-fixSymbolBar)/atr_baseSymbol
comparativeSymbol = request.security(comparativeTickerId, "60", close)
fixComparativeSymbolbar = request.security(comparativeTickerId, "D", close[1],barmerge.gaps_off, barmerge.lookahead_on) // correct
atrComparativeSymbol = request.security(comparativeTickerId,"60",ta.atr(25))
normalizeComparativeSymbol = (comparativeSymbol - fixComparativeSymbolbar)/atrComparativeSymbol
ma_function(source, length) =>
switch smoothing
"RMA" => ta.rma(source, length)
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
=> ta.wma(source, length)
res = (normalizeSymbolBar - normalizeComparativeSymbol)*100
//plot
plot(res,style = plot.style_columns, color = res > 0 ? color.blue : color.orange)
plot(ma_function(res,lengthFastMA), color = ma_function(res,lengthFastMA) > 0 ? #0c5847 : color.red, title = "Fast MA", linewidth = 2)
plot(ma_function(res,lengthSlowMA), style = plot.style_area, title = 'Slow MA', color = color.gray)
In short, this indicator calculate the different between the normalized return of a stock compared to that of an index.
Now i want to write an indicator on daily time frame using the end-of-day value of ta.ema(res,lengthFastMA) on 60 mins time frame to plot. For example, lets say the value of ta.ema(res,lengthFastMA) of 23 pm June 30th 2022 bar on 60 mins timeframe is 50, that makes the value of the indicator on daily time frame for June 30th 2022 is 50 too.
Anyone can help on this issue pls?. Thank you so much
my_timeframe = input.timeframe(title="Custom Timeframe", defval="1", group="Strategy parameters")
changed_data = request.security(syminfo.tickerid, my_timeframe, graph_data, gaps=barmerge.gaps_on)
plot(changed_data , title = "Your custom graph", color=color.orange)
For version 5: define timeframe input to allow customize from settings section, request security update with your timeframe that is different than deafult for your view, show graph.

Lua Date Difference

I want to know if you can get the date difference of two dates that are predefined or dynamic in a long run.
Do you need a proper date format when using this function?
function datediff(d1, d2, ...)
col_date1 = os.time({year = d1:year(), month = d1:month(), day = d1:day() , hour = d1:hour(), min = d1:minute(), sec = d1:second() })
col_date2 = os.time({year = d2:year(), month = d2:month(), day = d2:day() , hour = d2:hour(), min = d2:minute(), sec = d2:second() })
local arg={...}
if arg[1] ~= nil then
if arg[1] == "min" then
return math.abs((col_date1 - col_date2) / 60)
elseif arg[1] == "hour" then
return math.abs((col_date1 - col_date2) / 3600)
elseif arg[1] == "day" then
return math.abs((col_date1 - col_date2) / 86400)
end
end
return math.abs(col_date1 - col_date2)
--return 0
end
This is the code. But I have no idea how this work exactly.
The input should be like 31122017 - 31122016 is 1 year. or something like that.
This code takes custom date objects as input. So, for example, if you had a date object d that represented a date like 2017-05-22, then calling d:year() would give you the number 2017, d:hour() would give you the number 5, etc.
There are no functions to make objects like this in standard Lua, so the project this code is in must be using a separate date library. You need to find out how to create the date objects that your project expects, and then pass those into the function.

Timestamp pattern

Let's assume I have the following reminder timestamp
local reminder_timestamp = "2013-12-13T00:00:00+01:00"
And I'm using the below function to return time in UTC
local function makeTimeStamp(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d%d)%:?(%d%d)"
local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin = dateString:match(pattern)
local timestamp = os.time( {year=year, month=month, day=day, hour=hour, min=minute, sec=seconds} )
local offset = 0
if ( tzoffset ) then
if ( tzoffset == "+" or tzoffset == "-" ) then -- we have a timezone!
offset = offsethour * 60 + offsetmin
if ( tzoffset == "-" ) then
offset = offset * -1
end
timestamp = timestamp + offset
end
end
return timestamp
end
What should be the pattern above to match the reminder timestamp I mentioned earlier?
You need to use Lua's string parsing capabilities. Try a few of the techniques mentioned in the following, and if you still have issues, post specifically what is not working:
Question about splitting string and saving in several variables
Question about extracting data from a string, very similar to yours (although problem domain is GPS coordinates instead of date/time)
Question about how to do pattern matching in Lua, several good examples and links to docs
Here is the answer and the function actually works fine
pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%p])(%d%d)%:?(%d%d)"
reminder_timestamp = "2013-12-23T08:00:00+01:00"
local year, month, day, hour, minute, seconds, tzoffset, offsethour, offsetmin = reminder_timestamp:match(pattern)
Resource: http://www.lua.org/manual/5.1/manual.html#5.4.1

Convert & store String into currency values

I have a String and i need to convert it into Currency format in RUBY and
verify whether it matches to the expected.
String = "$6,178.50 USD / 22,693.01 AED"
I want to split it into 2 different variables like
usa_price = $6,178.50
aed_price = 22,693.01
expected_output= $6,178.50 * 3.67 = 22,693.01 (should match value in AED)
I tried doing gsub/scan and im confused now, what's the best way to
achieve this in Ruby!!!
I would split on the / and then use the money gem to parse the amounts out, like this:
require 'money'
amounts = "$6,178.50 USD / 22,693.01 AED".split("/")
amounts.map! { |amount| Money.parse(amount) }
Then, because they're now Money objects, you can do money things with them:
>> amounts.first.format
=> "$6,178.50"
If you're sure that first number is USD and second number is AED and the order won't change then:
str = "$6,178.50 USD / 22,693.01 AED"
usa_price, aed_price = str.scan(/\d{1,2}?,?\d{1,3}\.\d{2}/)
#=> usa_price = 6,178.50, aed_price = 22,693.01

Resources