I'm working on asp.net website.
I'm not able to count the only null values for particular id from the database Sqlserverce.
suppose I have table called Alarm
alarmid date
1 12/12/2010
2 Null
3 4/4/2010
5 12/05/2011
6 Null
Here I need to find count of null values. ie 2.
I used ISNULL with COUNT function but its not working.
How to find the null values count.
I tried like select count(date) where date is null. but not working.
pls help me out.
count(Null) isn't supposed to count anything, but you can give the count function something else. For example, 1
select
count(1)
where date is null.
In SQL Server you can do this hopefully it would work in CE
SELECT count(isnull([date],0)) as total
Update: This works in CE, above only works in SQL Server as isnull not supported in CE
select count(COALESCE(name ,1)) from test
where name is null
Related
I am using the Coalesce function to return a value from my preferred ranking of Columns but I also want to include the name of the column that the value was derived from.
`i.e
Table:
Apples Pears Mangos
4 5
**SQL **
; with CTE as
(
Select
Coalesce(Apples,Pears,Mangos) as QTY_Fruit
from Table
) select *, column name from QTY_Fruit
from CTE
Result:
QTY_Fruit Col Name
4 Pears`
I am trying to avoid a case statement if possible because there are about 12 fields that I will need to use in my Coalesce. Would love for an easy way to pull the column name based on value in QTY_Fruit. I'm all ears if the answer lies outside the use of subqueries but I figured this would be a start.
i am new to Power query and i would like to learn a bit more about it. I am facing the following problem. My table looks like this (empty fields already removed):
What i'm trying is to get a new table where "Spalte2" holds my list of ISINs and S^"Spalte 8" but also "Spalte 9" and "Spalte 10" hold my portfolio share (komma separated).
EDIT: For clarification I hope to get something like this:
EDIT: I try to get a table in here, hope it works:
Spalte1
Spalte2
Spalte8
Spalte9
Spalte10
Bâloise Holding AG
CH0012410517
1,04
Null
Null
Barry Callebaut AG
CH0009002962
0,63
Null
Null
Galenica AG
CH0360674466
0,58
Null
Null
Givaudan SA
CH0010645932
1,24
Null
Null
HelloFresh SE
DE000A161408
527.705,26
1,85
Null
Kering S.A.
FR0000121485
431.145,00
1,51
Null
Standard Chartered PLC
GB0004082847
4,610 117.699,50
Null
0,41
Unilever PLC
GB00B10RZP78
42,305 315.241,76
Null
1,11
What i'm trying to get is this:
Spalte2
Spalte8
CH0012410517
1,04
CH0009002962
0,63
CH0360674466
0,58
CH0010645932
1,24
DE000A161408
1,85
FR0000121485
1,51
GB0004082847
0,41
GB00B10RZP78
1,11
Which way can i use in PQ to match the ISIN with its portfolio share? Thanks a lot!
Thomas
Am I correct in understanding that you simply want to consolidate the information from the rightmost populated column of each row into one column, and disregard any other information between it and the first column?
If so, then this might be one possible approach.
Starting with a sample table called Table1 in power query:
I just add a new column and use if then statements to select the rightmost populated column's information:
(In the above M code, I check that each column is both not null and not blank, to be thorough.)
I get this result:
Then I select the Spalte2 and Custom columns and remove the other columns to get this:
I have the following data model:
Record: Id, ..., CreateDate
FactA: RecordId, CreateDate
FactB: RecordId, CreateDate
Relationships exist from FactA to Record and FactB to Record.
I've written measures on Records such as this with no issues:
FactA's:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA)
FactB's:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactB)
Now I'd like a count of Records with FactA but no FactB, in SQL I'd do a LEFT JOIN WHERE FactB.RecordId IS NULL but I can't figure out how to do similar in DAX. I've tried:
-- this returns blank, presumably because when there is a FactB then RecordId isn't blank, and when there is no Fact B then RecordId a NULL which isn't blank either
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA, FILTER(FactB, ISBLANK([RecordId])))
-- this returns the long "The value for columns "RecordId" in table "FactB" cannot be determined in the current context" error.
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FILTER(FactA, ISBLANK(FactB[RecordId])))
I've also tried various ways of using RELATED and RELATEDTABLE but I don't really understand enough about DAX and context to know what I'm doing.
Can someone explain how I can write the calculated measure to count Records with FactA but no FactB?
Thanks in advance.
Edit - Workaround
I've come up with this, it looks correct so far but I'm not sure if it is the generally correct way to do this:
-- Take the count with FactA and subtract the count of (FactA and FactB)
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA) - CALCULATE(DISTINCTCOUNT(Records[Id]), FactA, FactB)
Here's an alternative, that might still not be the best way of doing it:
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[ID]), FILTER(Records,CONTAINS(FactA, FactA[RecordID],Records[ID]) && NOT(CONTAINS(FactB,FactB[RecordID],Records[ID]))))
The difference between my version and yours is that mine returns a value of 1 for those items in and A but not B and BLANK for everything else. Your version returns 1 for those items in A but not B, 0 for those in both A and B and BLANK for everything else. Depending on your use case, one outcome may be prefereable over the other.
This question is somewhat similar to
Google Spreadsheet multiple column filter using OR
but where as he asks for the equivalent of:
select count(*)
from Table
where A is not null and (B is not null or C is not null)
I would like to do:
select count(*)
from Table
where A is not null OR (B is not null AND C is not null)
In fact what I am trying to do is filter on a date and I have been using
=FILTER(YEAR(Hours!A2:A)=2012,MONTH(Hours!A2:A)>=8)
to give me August going forward.
but now I need to add a limit to a certain day for the month. I would need something like this:
=FILTER(MONTH(Hours!A2:A)=8, ( MONTH(Hours!A2:A)=9 AND DAY(Hours!A2:A)<=13) )
in order to have all of August and then September only up to the 13th.
Is there a Syntax that allows this?
to have all of August and then September only up to the 13th.
One way (and this would be a "general" solution for filtering between two dates):
=COUNT(FILTER(Hours!A2:A;Hours!A2:A>=DATE(2012;8;1);Hours!A2:A<=DATE(2012;9;13)))
I have taken a good look at the Teradata Syntax reference to no avail
I have some rows with numbers:
ID
Mickey
Laura9
Larry59N
How do I take away the integers from my rows?
I understand that SUBSTR(id, 0, index(id, '%FORMAT%')) would work, but I don't know what could I enter in the %FORMAT% area to just find integers.
You can use oTranslate to remove numbers:
BTEQ -- Enter your SQL request or BTEQ command:
Select the_name, oTranslate( the_name, 'a0123456789','a')
from
( SELECT 'Larry59N' the_name FROM ( SELECT 'X' DUMMY ) a
UNION ALL
SELECT 'Laura9' FROM ( SELECT 'X' DUMMY ) b
UNION ALL
SELECT 'Mickey' the_name FROM ( SELECT 'X' DUMMY ) c
) d
;
*** Query completed. 3 rows found. 2 columns returned.
*** Total elapsed time was 1 second.
the_name oTranslate(the_name,'a0123456789','a')
-------- -----------------------------------------------------
Larry59N LarryN
Laura9 Laura
Mickey Mickey
HTH.
Cheers.
Unfortunately, I don't believe there is a function native to Teradata that will accomplish this. I would suggest looking at the UDF's posted on the Teradata Developer Exchange (link). The function eReplaceChar in particular looks like it may help you accomplish what you are looking to do with this data. The UDF's found at the link above were published under the Apache 2.0 license so you should not have any problems using them.