I have values in my db as follows
1
2
2A
.......
10
10A
.......
250A
......
300
and i need to find the records that are within range 1-10,11-20,....291-300
can't figure out how to do this as there are characters after number
I'm using postgres db so i can apply regex query on db
You can use:
SUBSTRING(mycolumn FROM '^[0-9]+')
in order to extract the number that is at the start of your column.
To perform the filtering you want, you can use:
SELECT *
FROM mytable
WHERE CAST(SUBSTRING(mycolumn FROM '^[0-9]+') AS INT) BETWEEN 1 AND 10
Demo here
Related
I have 2 cols
SID CID
1 101,102
2 201,2021,231
IN TGT
SID CID
1 101
1 102
2 201
2 2021
2 231
You need to use normalizer.
First after SQ, use expression transformation to split CID column.
o_cid1= substr(cid,1,3) --if length is variable you need to use instr
o_cid2= substr(cid,instr(cid,',',1)+1, 3) -- if length is variable you need to use instr
...
Then use normalizer. Properties should be
Number of occurrences of sid =0
Number of occurrences of cid =3
You will see 4input ports(3for for cid1,2,3 and 1for sid) and two outports(1cid,1sid) related to your needs.
Conect sid, o_cid1,o_cid2... To corresponding ports.
Finally connect output ports cid,sid to target.
How do I extract month as 2 digits from a date field?
My current query:
EXTRACT(MONTH FROM TransactionDate) as CalendarPeriod,
Example:
2021-07-13 returns 7
Required Output
2021-07-13 should return 07
Use below instead
cast(TransactionDate as string format('MM')) CalendarPeriod
I have a table containing :
VideoID Views DeviceType
1 12 Desktop
1 30 Mobile
1 95 Tablette
...
I want to create a slicer names Views Ranges with ranges like below to filter videos by the sum of their views :
From 100 to 1000
From 1001 to 10000
...
VideoID 1 has a total 137 of views, so when I choose From 100 to 1000 in the filter it will be show.
This is what I tried :
Range =
VAR ranges =[Total Views]
RETURN
SWITCH(TRUE(),
ranges <= 100, "From 0 to 100",
ranges <= 10000, "From 100 to 10,000",
ranges <= 20000, "From 10,000 to 20,000",
....
)
But the filter is empty.
This appears to fit the Basic Category of the Static Segmentation pattern. It's explained in full detail here:
https://www.daxpatterns.com/static-segmentation/
To summarize: I would add a DAX Calculated Column to your first table ("Views"?) to return the Key from a table of ranges. You can then use that Key to establish a relationship to the table of ranges. With the relationship in place, you can use the table of ranges to filter in a Slicer, or categorize in any other visual.
I am working on a model in Power BI that has two datasets:
Set_1 (just a list of each group name)
Group:
1
2
3
and Set_2, a bunch of values per group in a different dataset:
Group: Value:
1 10
1 20
1 -7
2 100
2 -25
3 45
3 15
1 3
The tables are related by group. I want to create a measure on Set_1 that shows the sum of the values by group in Set_2. I can do so with the following DAX formula:
GroupSum = CALCULATE(SUMX(Set_2, Set_2[Value]))
looks like this
Group: GroupSum:
1 26
2 75
3 60
But I don't understand why the CALCULATE function, which doesn't take any filter contexts as parameters works the way it does in this instance. Without the CALCULATE function,
GroupSum = SUMX(Set_2, Set_2[Value])
looks like this:
Group: GroupSum:
1 161
2 161
3 161
Which makes sense. I just need help understanding how the Calculate function works, specifically when it isn't passed any filter parameters.
EDIT: The answer lies in the concept of "context transition" as pointed out below.
Using the CALCULATE function makes the DAX perform a context transition.
CALCULATE transforms all existing row contexts into an equivalent filter context before applying its filter arguments to the original filter context.
For more detail on this, check out the site I quoted above:
Understanding Context Transition.
In your example, the value in the Group column of each row acts as a filter when you use CALCULATE as if you had written something like CALCULATE(SUM(Set_2[Value]), Set_2[Group] = 1). Even though it doesn't have an explicit filter, the row context acts as a filter.
I want to be able to compare two tables within the same SQLite Database using a C++ interface for matching records. Here are my two tables
Table name : temptrigrams
ID TEMPTRIGRAM
---------- ----------
1 The cat ran
2 Compare two tables
3 Alex went home
4 Mark sat down
5 this database blows
6 data with a
7 table disco ninja
++78
Table Name: spamtrigrams
ID TRIGRAM
---------- ----------
1 Sam's nice ham
2 Tuesday was cold
3 Alex stood up
4 Mark passed out
5 this database is
6 date with a
7 disco stew pot
++10000
The first table has two columns and 85 records and the second table has two columns with 10007 records.
I would like to take the first table and compare the records within the TEMPTRIGRAM column and compare it against the TRIGRAM columun in the second table and return the number of matches across the tables. So if (ID:1 'The Cat Ran' appears in 'spamtrigrams', I would like that counted and returned with the total at the end as an integer.
Could somebody please explain the syntax for the query to perform this action?
Thank you.
This is a join query with an aggregation. My guess is that you want the number of matches per trigram:
select t1.temptrigram, count(t2.trigram)
from table1 t1 left outer join
table2 t2
on t1.temptrigram = t2.trigram
group by t1.temptrigram;
If you just want the number of matches:
select count(t2.trigram)
from table1 t1 join
table2 t2
on t1.temptrigram = t2.trigram;