Grouping tags by processes - grouping

I have a variable that is being collected over time, during a process. The process starts when the STATUS is equal to 2 and ends when the STATUS is equal to 11. What I need to develop in kusto an ID column, which groups the tag values each time the process runs. Can you help me with this?

below is one option to generate the Id column, using row_cumsum(), and based on the input dataset you've provided. It may give you a direction to implement your full solution
datatable(timestamp:datetime, tag:string, value:double, status:int)
[
datetime(2020-07-04 12:00), 'Tag1', 15.2391, 2,
datetime(2020-07-04 12:02), 'Tag1', 13.452, 2,
datetime(2020-07-04 12:04), 'Tag1', 17.239, 4,
datetime(2020-07-04 12:15), 'Tag1', 21.891, 4,
datetime(2020-07-04 12:17), 'Tag1', 18.9, 11,
datetime(2020-07-04 12:30), 'Tag1', 12, 2,
datetime(2020-07-04 12:32), 'Tag1', 15, 2,
datetime(2020-07-04 12:33), 'Tag1', 9, 2,
datetime(2020-07-04 12:45), 'Tag1', 17.5, 4,
datetime(2020-07-04 12:48), 'Tag1', 42, 11,
datetime(2020-07-04 13:12), 'Tag1', 22, 2,
datetime(2020-07-04 13:20), 'Tag1', 19, 7,
datetime(2020-07-04 13:50), 'Tag1', 51, 7,
datetime(2020-07-04 14:10), 'Tag1', 39, 8,
datetime(2020-07-04 14:20), 'Tag1', 37, 11,
]
| order by tag asc, timestamp asc, status asc
| extend Id = toint(prev(status) == 11)
| extend Id = 1 + row_cumsum(Id)
-->
| timestamp | tag | value | status | Id |
|-----------------------------|------|---------|--------|----|
| 2020-07-04 12:00:00.0000000 | Tag1 | 15.2391 | 2 | 1 |
| 2020-07-04 12:02:00.0000000 | Tag1 | 13.452 | 2 | 1 |
| 2020-07-04 12:04:00.0000000 | Tag1 | 17.239 | 4 | 1 |
| 2020-07-04 12:15:00.0000000 | Tag1 | 21.891 | 4 | 1 |
| 2020-07-04 12:17:00.0000000 | Tag1 | 18.9 | 11 | 1 |
| 2020-07-04 12:30:00.0000000 | Tag1 | 12 | 2 | 2 |
| 2020-07-04 12:32:00.0000000 | Tag1 | 15 | 2 | 2 |
| 2020-07-04 12:33:00.0000000 | Tag1 | 9 | 2 | 2 |
| 2020-07-04 12:45:00.0000000 | Tag1 | 17.5 | 4 | 2 |
| 2020-07-04 12:48:00.0000000 | Tag1 | 42 | 11 | 2 |
| 2020-07-04 13:12:00.0000000 | Tag1 | 22 | 2 | 3 |
| 2020-07-04 13:20:00.0000000 | Tag1 | 19 | 7 | 3 |
| 2020-07-04 13:50:00.0000000 | Tag1 | 51 | 7 | 3 |
| 2020-07-04 14:10:00.0000000 | Tag1 | 39 | 8 | 3 |
| 2020-07-04 14:20:00.0000000 | Tag1 | 37 | 11 | 3 |

Related

Conditional count Measure

I have data looking like this:
| ID |OpID|
| -- | -- |
| 10 | 1 |
| 10 | 2 |
| 10 | 4 |
| 11 |null|
| 12 | 3 |
| 12 | 4 |
| 13 | 1 |
| 13 | 2 |
| 13 | 3 |
| 14 | 2 |
| 14 | 4 |
Here OpID 4 means 1 and 2.
I would like to count the different occurrences of 1, 2 and 3 in OpID of distinct ID.
If the counts of OpID having 1 would be 4, 2 would be 4, 3 would be 2.
If ID has OpID of 4 but already has data of 1, 2 it wouldn't be counted. But if 4 exists and only 1 (2) is there, count for 2 (1) would be incremented.
The expected output would be:
|OpID|Count|
| 1 | 4 |
| 2 | 4 |
| 3 | 2 |
(Going to be using the results in a column chart)
Hope this makes sense...
edit: there are other columns too and an ID and OpID can be duplicated hence need to do a groupby clause before.

How to Sum all working days for each month but restart from 0 for every month in power Bi Dax

I would like to know how could I get the Sum of all working days for specific month but in the table starting each month's Sum over again.
This is my DateTable Now with this query for Work Days Sum:
Work Days Sum =
CALCULATE (
SUM ( 'DateTable'[Is working Day] ),
ALL ( 'DateTable' ),
'DateTable'[Date] <= EARLIER ( 'DateTable'[Date] )
)
Date | Month Order | Is working day | Work Days Sum |
January - 21 331
2022/01/01 | 1 | 0 | |
2022/01/02 | 1 | 0 | |
2022/01/03 | 1 | 1 | 1 |
2022/01/04 | 1 | 1 | 2 |
2022/01/05 | 1 | 1 | 3 |
2022/01/06 | 1 | 1 | 4 |
.....
2022/01/27 | 1 | 1 | 19 |
2022/01/28 | 1 | 1 | 20 |
2022/01/29 | 1 | 0 | 20 |
2022/01/30 | 1 | 0 | 20 |
2022/01/31 | 1 | 1 | 21 |
February 20 890
2022/02/01 | 2 | 1 | 22 |
2022/02/02 | 2 | 1 | 23 |
2022/02/03 | 2 | 1 | 24 |
2022/02/04 | 2 | 1 | 25 |
|
|
V
Date | Month Order | Is working day | Work Days Sum |
January - 21 21
2022/01/01 | 1 | 0 | |
2022/01/02 | 1 | 0 | |
2022/01/03 | 1 | 1 | 1 |
2022/01/04 | 1 | 1 | 2 |
2022/01/05 | 1 | 1 | 3 |
2022/01/06 | 1 | 1 | 4 |
.....
2022/01/27 | 1 | 1 | 19 |
2022/01/28 | 1 | 1 | 20 |
2022/01/29 | 1 | 0 | 20 |
2022/01/30 | 1 | 0 | 20 |
2022/01/31 | 1 | 1 | 21 |
February 20 41
2022/02/01 | 2 | 1 | 1 |
2022/02/02 | 2 | 1 | 2 |
2022/02/03 | 2 | 1 | 3 |
2022/02/04 | 2 | 1 | 4 |
2022/02/05 | 2 | 0 | 4 |
.....
Any idea on how I can change my dax query to achieve output of second table below the down arrow would be much appreciated.

Create column to classify rows based on realted tables DAX PowerBI

I have simplified my problem to solve. Lets suppose I have three tables. One containing data and specific codes that identify objects lets say Apples.
+-------------+------------+-----------+
| Data picked | Color code | Size code |
+-------------+------------+-----------+
| 1-8-2018 | 1 | 1 |
| 1-8-2018 | 1 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 2 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 3 | 3 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 5 | 3 |
| 1-8-2018 | 6 | 1 |
| 1-8-2018 | 6 | 2 |
| 1-8-2018 | 6 | 2 |
+-------------+------------+-----------+
And i have two related helping tables to help understand the codes (their relationships are inactive in the model due to ambiguity with other tables in the real case).
+-----------+--------+
| Size code | Size |
+-----------+--------+
| 1 | Small |
| 2 | Medium |
| 3 | Large |
+-----------+--------+
and
+------------+----------------+-------+
| Color code | Color specific | Color |
+------------+----------------+-------+
| 1 | Light green | Green |
| 2 | Green | Green |
| 3 | Semi green | Green |
| 4 | Red | Red |
| 5 | Dark | Red |
| 6 | Pink | Red |
+------------+----------------+-------+
Lets say that I want to create an extra column in the original table to determine which apples are class A and class B given that medium green Apples are class A and large Red apples are class B, the other remain blank as the example below.
+-------------+------------+-----------+-------+
| Data picked | Color code | Size code | Class |
+-------------+------------+-----------+-------+
| 1-8-2018 | 1 | 1 | |
| 1-8-2018 | 1 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 2 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 3 | 3 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 5 | 3 | B |
| 1-8-2018 | 6 | 1 | |
| 1-8-2018 | 6 | 2 | |
| 1-8-2018 | 6 | 2 | |
+-------------+------------+-----------+-------+
What's the proper DAX to use given the relationships are initially inactive. Preferably solvable without creating any further additional columns in any table. I already tried codes like:
CALCULATE (
"A" ;
FILTER ( 'Size Table' ; 'Size Table'[Size] = "Medium");
FILTER ( 'Color Table' ; 'Color Table'[Color] = "Green")
)
And many variations on the same principle
Given that the relationships are inactive, I'd suggest using LOOKUPVALUE to match ID values on the other tables. You should be able to create a calculated column as follows:
Class =
VAR Size = LOOKUPVALUE('Size Table'[Size],
'Size Table'[Size code], 'Data Table'[Size code])
VAR Color = LOOKUPVALUE('Color Table'[Color],
'Color Table'[Color code], 'Data Table'[Color code])
RETURN SWITCH(TRUE(),
(Size = "Medium") && (Color = "Green"), "A",
(Size = "Large") && (Color = "Red"), "B", BLANK())
If your relationships are active, then you don't need the lookups:
Class = SWITCH(TRUE(),
(RELATED('Size Table'[Size]) = "Medium") &&
(RELATED('Color Table'[Color]) = "Green"),
"A",
(RELATED('Size Table'[Size]) = "Large") &&
(RELATED('Color Table'[Color]) = "Red"),
"B",
BLANK())
Or a bit more elegantly written (especially for more classes):
Class =
VAR SizeColor = RELATED('Size Table'[Size]) & " " & RELATED('Color Table'[Color])
RETURN SWITCH(TRUE(),
SizeColor = "Medium Green", "A",
SizeColor = "Large Red", "B",
BLANK())

SAS:add one column from tableB to tableA

I have two table looks like and I want to add column score to tableA from tableB, then get tableC, how to do in SAS?
the only rule is to add a column in tableA name "score " and its value is same as column "score" in tableB (which are all the same in tableB)
+----+---+---+---+
| id | b | c | d |
+----+---+---+---+
| 1 | 5 | 7 | 2 |
| 2 | 6 | 8 | 3 |
| 3 | 7 | 8 | 1 |
| 4 | 5 | 7 | 2 |
| 5 | 6 | 8 | 3 |
| 6 | 7 | 8 | 1 |
+----+---+---+---+
tableA
+---+---+-------+
| e | f | score |
+---+---+-------+
| 3 | 7 | 11 |
| 4 | 6 | 11 |
| 5 | 5 | 11 |
+---+---+-------+
tableB
+----+---+---+---+-------+
| id | b | c | d | score |
+----+---+---+---+-------+
| 1 | 5 | 7 | 2 | 11 |
| 2 | 6 | 8 | 3 | 11 |
| 3 | 7 | 8 | 1 | 11 |
| 4 | 5 | 7 | 2 | 11 |
| 5 | 6 | 8 | 3 | 11 |
| 6 | 7 | 8 | 1 | 11 |
+----+---+---+---+-------+
tableC
If the "id" is present in both tables, you can use the following to create Table C:
PROC SQL;
CREATE TABLE tableC AS
SELECT a.*, b.score
FROM tableA a JOIN tableB b
ON a.id = b.id;
QUIT;
Please confirm that this is what you need?

How to write a Django query where coloum_value < 100?

I have a table like this in DJango?
| id | user_id | name | source | remaining | start_date | time_remaining | size |
+----+---------+---------------+----------------+-----------+----------------------------+----------------+------+
| 1 | 1 | ok.txt | ngs.pradhi.com | 20 | February 05, 2013, 08:01AM | 1 | 4 MB |
| 2 | 1 | NC_008253.fna | ngs.pradhi.com | 20 | February 05, 2013, 08:02AM | 1 | 4 MB |
| 3 | 1 | test.data | ngs.pradhi.com | 0 | February 05, 2013, 08:21AM | 1 | 4 MB
I want to retrieve the data where user_id = request.user.id and remaining < 100.
Tried using:
Queue.objects.filter(user_id=request.user.id, remaining < 100) But didn't work.
Queue.objects.filter(user_id=request.user.id, remaining__lt=100).exclude(remaining=0)
Django Field lookups