I am working on a report haveing data like below
id Item Brand Size Area Rate Amount height width Material image
3 item1 Brand1 100 x 200 2.44 20 20 100 200 Material1 Image1
3 item2 Brand2 100 x 200 1 30 30 100 200 Material2 Image1
3 item3 Brand3 100 x 200 1 40 40 100 200 Material3 Image1
4 item1 Brand1 100 x 200 2.44 15 15 100 200 Material1 Image2
4 item2 Brand2 100 x 200 1 30 30 100 200 Material2 Image2
4 item3 Brand3 100 x 200 1 45 45 100 200 Material3 Image2
In Report i have to show the image on top, data in table below for id 3, on next page image2 and data with id 4. this is a long list like this.
I can show image dynamically in the report, but the problem is grouping and format.I am doing it using dataset in asp.net. Any suggestion or guidance ? I have spent several hours but not figured it out.
Make a group by id column.
Then, in the group header, show the image.
In detail session, show the rest of the data.
Finally, tell the group header to "new page before" if group number > 1.
Related
I have a line chart in PowerBi that shows the price of an index every hour. How can I show in the same chart the daily average of prices?
I have computed a measure which calculates it, but when i plot in the hourly chart the average is no longer daily but hourly.
Here is an example: for simplicity, let us say that days have 3 hours, what I want to compute in PowerBi is the last column:
day
hour
price
daily_average
1/1/2023
1
100
150
1/1/2023
2
150
150
1/1/2023
3
200
150
1/2/2023
1
50
60
1/2/2023
2
60
60
1/2/2023
3
70
60
I would like to plot a graph with both "price" and "daily_average".
What you need to do is to create a measure where you remove Hour from filtere context, ALL(Sample1[hour]):
DailyAVG = CALCULATE( AVERAGE(Sample1[price]), ALL(Sample1[hour]) )
Initial Table
company time value
-------------------------
a 00:00:15.000 100
a 00:00:30.000 100
b 00:01:00.000 100
a 00:01:10.000 100
a 00:01:15.000 100
a 00:01:20.000 300
a 00:01:25.000 100
b 00:01:30.000 400
a 00:01:50.000 100
a 00:02:00.000 100
a 00:00:03.000 200
Let t = 1 hour.
For each row, I would like to look back t time.
Entries falling in t will form a time window. I would like to get max(time window) - min (time window) / number of events).
For example, if it is 12:00 now, and there are a total of five events, 12:00, 11:50, 11:40, 11:30, 10:30, four of which falls in the window of t i.e. 12:00, 11:50, 11:40, 11:30, the result will be 12:00 - 11:30 / 4.
Additionally, the window should only account for rows with the same value and company name.
Resultant Table
company time value x
--------------------------------
a 00:00:15.000 100 0 (First event A).
a 00:00:30.000 100 15 (30 - 15 / 2 events).
b 00:01:00.000 100 0 (First event of company B).
a 00:01:10.000 100 55/3 = 18.33 (1:10 - 0:15 / 3 events).
a 00:01:15.000 100 60/4 = 15 (1:15 - 0:15 / 4 events).
a 00:01:20.000 300 0 (Different value).
a 00:01:25.000 100 55/4 = 13.75 (01:25 - 0:30 / 4 events).
b 00:01:30.000 400 0 (Different value and company).
a 00:01:50.000 100 40/4 = 10 (01:50 - 01:10 / 4 events).
a 00:02:00.000 100 50/5 = 10 (02:00 - 01:10 / 5 events).
a 00:03:00.000 200 0 (Different value).
Any help will be greatly appreciated. If it helps, I asked a similar question, which worked splendidly: Sum values from the previous N number of days in KDB?
Table Query
([] company:`a`a`b`a`a`a`a`b`a`a`a; time: 00:00:15.000 00:00:30.000 00:01:00.000 00:01:10.000 00:01:15.000 00:01:20.000 00:01:25.000 00:01:30.000 00:01:50.000 00:02:00.000 00:03:00.000; v: 100 100 100 100 100 300 100 400 100 100 200)
You may wish to use the following;
q)update x:((time-time[time binr time-01:00:00])%60000)%count each v where each time within/:flip(time-01:00:00;time) by company,v from t
company time v x
---------------------------------
a 00:15:00.000 100 0
a 00:30:00.000 100 7.5
b 01:00:00.000 100 0
a 01:10:00.000 100 18.33333
a 01:15:00.000 100 15
a 01:20:00.000 300 0
a 01:25:00.000 100 13.75
b 01:30:00.000 400 0
a 01:50:00.000 100 10
a 02:00:00.000 100 10
a 03:00:00.000 200 0
It uses time binr time-01:00:00 to get the index of the min time for the previous 1 hour of each time.
Then (time-time[time binr time-01:00:00])%60000 gives the respective time range (i.e., time - min time) for each time in minutes.
count each v where each time within/:flip(time-01:00:00;time) gives the number of rows within this range.
Dividing the two and implementing by company,v applies it all only to those that have the same company and v values.
Hope this helps.
Kevin
If your table is ordered by time then below solution will give you the required result. You can also order your table by time if it is not already using xasc.
I have also modified the table to have time with different hour values.
q) t:([] company:`a`a`b`a`a`a`a`b`a`a`a; time: 00:15:00.000 00:30:00.000 01:00:00.000 01:10:00.000 01:15:00.000 01:20:00.000 01:25:00.000 01:30:00.000 01:50:00.000 02:00:00.000 03:00:00.000; v: 100 100 100 100 100 300 100 400 100 100 200)
q) f:{(`int$x-x i) % 60000*1+til[count x]-i:x binr x-01:00:00}
q) update res:f time by company,v from t
Output
company time v res
---------------------------------
a 00:15:00.000 100 0
a 00:30:00.000 100 7.5
b 01:00:00.000 100 0
a 01:10:00.000 100 18.33333
a 01:15:00.000 100 15
a 01:20:00.000 300 0
a 01:25:00.000 100 13.75
b 01:30:00.000 400 0
a 01:50:00.000 100 10
a 02:00:00.000 100 10
a 03:00:00.000 200 0
You can modify the function f to change time window value. Or change f to accept that as an input parameter.
Explanation:
We pass time vector by company, value to a function f. It deducts 1 hour from each time value and then uses binr to get the index of the first time entry within 1-hour window range from the input time vector.
q) i:x binr x-01:00:00
q) 0 0 0 0 1 2 2
After that, it uses the indexes of the output to calculate the total count. Here I am multiplying the count by 60000 as time differences are in milliseconds because it is casting it to int.
q) 60000*1+til[count x]-i
q) 60000 120000 180000 240000 240000 240000 300000
Then finally we subtract the min and max time for each value and divide them by the above counts. Since time vector is ordered(ascending), the input time vector can be used as the max value and min values are at indexes referred by i.
q) (`int$x-x i) % 60000*1+til[count x]-i
I'm trying to reshape an array but I'm having some issues.
I have an array see image below and I'm trying to get it to look like / follow the pattern in the row highlighted in yellow. (note: I'm not trying to calculate the array but reshape it so it follows a pattern)
aa=[1:5;10:10:50;100:100:500]
aa_new=reshape(aa',[1 numel(aa)])
aa_new produces:
1 2 3 4 5 10 20 30 40 50 100 200 300 400 500
I'm trying to get:
1 2 3 4 5 50 40 30 20 10 100 200 300 400 500
Reverse the column numbers of every second row i.e.
aa(2:2:end,:) = aa(2:2:end, end:-1:1);
Now you're good to go with reshaping:
aa = reshape(aa.', 1, []);
I have a table, which is :
t:([]a:1 3 2 1 2 3 3 2 1;b:10 20 30 40 50 60 70 80 90;c:100 200 300 400 500 600 700 800 900)
And I want all c to be 0 where a is equal to 2, and all be to be 0 where a is equal to 1.
Currently I have these two codes:
t:update b:0 from t where a=1
t:update c:0 from t where a=2
My question is how to combine these two lines of codes into one. Because I am working on a table which is far bigger than this simple example and it will take me a lot of rows of codes to do all the updates, which is too long.
You can use vector conditional for this:
update b:?[a=1;0;b], c:?[a=2;0;c] from t
Here is my problem:
I have two tables:
q)t1:([]sym:1 5;x: 90 90)
q)t2:([]sym: 2 3 4 6 7 8; y: 100 200 300 400 500 600)
If I do aj[`sym;t2;t1], all the 6 columns in the result table will contain x with value 90.
But what I want is value 90 in column x only in row with sym 2 and 6, i.e the first time that sym in table t2 appear before table t1.
In other words, I want the result table to be like this:
q)([]sym:2 3 4 6 7 8; y: 100 200 300 400 500 600; x:90 0N 0N 90 0N 0N)
sym y x
----------
2 100 90
3 200
4 300
6 400 90
7 500
8 600
Could anyone tell me how I can achieve this? Thank you so much!
Not sure if aj can be used in this sense. This might give you what you need:
q)t2 lj 1!update sym:{x x binr y}[t2.sym;sym] from t1
sym y x
----------
2 100 90
3 200
4 300
6 400 90
7 500
8 600
Uses binr to find the next value greater than the value in t1 then joins only on that.
EDIT: note also that binr is >= ..... If you need strictly greater than you could use:
q)t2 lj 1!update sym:{x 1+x bin y}[t2.sym;sym] from t1
sym y x
----------
2 100 90
3 200
5 300
6 400 90
7 500
8 600
You can do aj to get the index where nearest smaller number of x will fit in, then a vector condition to get x when that index has got incremented, i.e.
select sym, y, x:?[c>prev c;x;0n] from aj[`sym; t2; update c:i from t1]