SoftadminApi.Kpi_ComputeTrend

Type: Table-valued function

Use to help you calculate the values of a trend to show in InfoSQL. See the Detailview documentation for an explanation of all KPI features.

Example

	DECLARE
		@CurrentProfit numeric(10,1) = 12345,
		@PrevProfit    numeric(10,1) = 9999;

	SELECT
	(
		SELECT
			'Profit'       AS [Label],
			@CurrentProfit AS [Value],
			'SEK'          AS [Unit],
			T.DiffPercent  AS [Trend.Value],
			'%'            AS [Trend.Unit],
			T.[Trend.Direction],
			T.[Trend.Type]
		FROM
			SoftadminApi.Kpi_ComputeTrend(@CurrentProfit, @PrevProfit, 1) T
		FOR JSON PATH
	) AS Kpi;

Parameters

@CurrentValue mandatory numeric
The current value.
@PreviousValue mandatory numeric
The value we compare the current value to in order to compute the trend.
@IncreaseIsGood mandatory bit
If an increasing trend is a good thing (an increase in profits is good) or bad thing (an increase in complaints is bad).

Resultsets

Resultset: Return value

Table count: repeated exactly once
Row count: exactly one row
Columns
Diff mandatory decimal
The difference between @CurrentValue and @PreviousValue. For example, if current is 81 and previous is 60 then Diff is 21.
DiffPercent mandatory decimal
The difference between @CurrentValue and @PreviousValue in percent. For example, if current is 81 and previous is 60 then DiffPercent is 35%.
Trend.Direction mandatory string
Whether the trend is increasing, decreasing, or neither. You can pass this string directly to an InfoSQL KPI.
Trend.Type mandatory string
Whether the trend is positive, negative, or neutral. You can pass this string directly to an InfoSQL KPI.