Skip to content

Instantly share code, notes, and snippets.

View ralfbecher's full-sized avatar

Ralf Becher ralfbecher

View GitHub Profile
@ralfbecher
ralfbecher / QlikView_Haversine_formula.qvs
Created December 16, 2015 20:11
QlikView Haversine formula calculation
// calculation of distance of two geo references (lat/lon):
= 12742 * atan2(sqrt(sqr(sin(((lat2-lat1)*PI()/180)/2))
+ (cos(lat1*PI()/180) * cos(lat2*PI()/180))
* pow(sin(((lon2-lon1)*PI()/180)/2),2)),
sqrt(1 - (sqr(sin(((lat2-lat1)*PI()/180)/2))
+ (cos(lat1*PI()/180) * cos(lat2*PI()/180))
* pow(sin(((lon2-lon1)*PI()/180)/2),2))))
@ralfbecher
ralfbecher / QlikView_Expression_NewProductPerYear.qvs
Last active October 21, 2015 20:03
QlikView Chart Expression Counts New Products/Year
data:
LOAD * INLINE [
Year, Product
2010, P1
2011, P1
2012, P1
2010, P2
2011, P2
2011, P3
2012, P3
@ralfbecher
ralfbecher / dateFromQlikNumber.js
Last active March 30, 2019 17:24
JavaScript function to create a Date from QlikView or Qlik Sense numerical Date value
function dateFromQlikNumber(n) {
var d = new Date(Math.round((n - 25569) * 86400000));
// since date was created in UTC shift it to the local timezone
d.setTime(d.getTime() + d.getTimezoneOffset() * 60000);
return d;
}
@ralfbecher
ralfbecher / QlikView_transform_matrix_into_adjacencylist.qvs
Last active September 26, 2015 20:20
QlikView transform matrix into adjacencylist
// matrix has numeric field names starting from "0" and a record number:
for i=0 to 34
for j=0 to 34
adj_list:
LOAD $(i) as node1,
$(j) as node2,
"$(j)" as measure
resident matrix
Where rec - 1= $(i) and "$(j)" > 0;
next
@ralfbecher
ralfbecher / QlikView_color_code_percentage_of_max_value.qvs
Created August 23, 2015 18:32
QlikView color code percentage of max value
=Replace(
ColorMix2 (if(rangemin(.90,rangemax( Sum(value) / Max({1} TOTAL value),.50))<.75,-Sqrt(-(rangemin(.90,rangemax( Sum(value) / Max({1} TOTAL value),.50))-.75)/(.75-.50)),Sqrt((rangemin(.90,rangemax( Sum(value) / Max({1} TOTAL value),.50))-.75)/(.90-.75))), RGB(255, 0, 0), RGB(0, 255, 0), RGB(255, 255, 0))
,'ARGB(255,','RGB(')
@ralfbecher
ralfbecher / QlikView_color_code_temperature_Celsius.qvs
Created August 21, 2015 22:03
QlikView color code for temperature in Celsius
// calculates hue for temperature from -30 to +30 °C:
hsl((30 + 240 * (30 - max({<Etage={EG}>} Temp)) / 60) / 255, 0.75, 0.9)
@ralfbecher
ralfbecher / Qlik_Sense_example_extension_with_switchable_user_custom_properties.js
Last active September 15, 2015 18:19
Qlik Sense example extension with switchable user custom properties
/**
* @owner Ralf Becher, irregular.bi
*/
define( ["jquery", "qlik"],
function ($, qlik) {
return {
//property panel
definition: {
type: "items",
component: "accordion",
@ralfbecher
ralfbecher / Neo4j-2.2_ajax_authentication_example.js
Created March 12, 2015 15:25
Neo4j 2.2 AJAX authentication example
$.ajaxSetup({
headers: {
"Authorization": 'Basic ' + window.btoa(username+":"+password)
}
});
$.ajax(txUrl(), {
type: "POST",
data: JSON.stringify({
statements: [{
statement: query,
@ralfbecher
ralfbecher / QlikView_get_and_format_microseconds.qvs
Last active August 29, 2015 14:16
QlikView get and format microseconds
//Formula to optain microseconds from TimeField:
LOAD ((frac(TimeField) * 86400000) - floor(frac(TimeField) * 86400000)) * 1000 as Micro
FROM ...;
//Use this formula for formatting:
LOAD Timestamp(TimeField - (Micro/86400000000)) & Num(floor(Micro), '000') as TimeStamp
FROM ...;
@ralfbecher
ralfbecher / QlikView_Extension_Load_JavaScript_via_RequireJS_to_solve_UTF-8_issue.js
Last active August 29, 2015 14:06
QlikView Extension Load JavaScript via RequireJS to solve UTF-8 issue
// thanks to Stefan Walther for giving a hint an this matter: https://github.com/stefanwalther
Qv.LoadExtensionScripts([_path + 'js/require.js'],
function () {
require([_path + 'js/d3.v3', _path + 'js/nv.d3.min', _path + 'js/interactiveLayer', _path + 'js/utils'],
function () {
Qv.AddExtension(_extension,
function () {
// render it..