Announcements
cancel
Showing results for
Did you mean:
Contributor III

## Trendline

Hello,

I have the following table:

And I created a graph of average item cost per command, but I need to add a trend line. I tried multiple ideas posted on the community but I did not succeed to have my trend line.

Example:

1. linest_m(total aggr(if(COST/[NB ITEMS],COST/[NB ITEMS]),Command),Command)*
2. only({1}Command)+linest_b(total aggr(if(COST/[NB ITEMS],COST/[NB ITEMS]),Command),Command)

bellow graph in excel, and the trendline in orange I need in qlick sense:

Thanks a lot for your help.

1 Solution

Accepted Solutions
MVP

First ,

Create a new dimension is ur script (numeric) as follow:

subfield(Command,' ',2) as CommandNum, (this is to transform ur commands from command 1 to 1 etc

then, use a combined graph;

as dimension:

='Command '&CommandNum

as a measure:

1)sum(COST) / Sum([NB ITEMS]) : as bar

2)

linest_m(total aggr(sum(COST) / Sum([NB ITEMS]),CommandNum),CommandNum)*CommandNum

+linest_b(total aggr(sum(COST) / Sum([NB ITEMS]),CommandNum),CommandNum)  : as line

sort as follow:

result:

4 Replies
MVP
MVP

First ,

Create a new dimension is ur script (numeric) as follow:

subfield(Command,' ',2) as CommandNum, (this is to transform ur commands from command 1 to 1 etc

then, use a combined graph;

as dimension:

='Command '&CommandNum

as a measure:

1)sum(COST) / Sum([NB ITEMS]) : as bar

2)

linest_m(total aggr(sum(COST) / Sum([NB ITEMS]),CommandNum),CommandNum)*CommandNum

+linest_b(total aggr(sum(COST) / Sum([NB ITEMS]),CommandNum),CommandNum)  : as line

sort as follow:

result:

Contributor III
Author

Many Thanks! The step I missed is X axis should be numeric and not text.

Contributor