I need to show, on a bar chart, this values:
Project 2013-01 2013-02 2013-03 2013-04 2013-05 2013-06
A 15 null null null null null
B null 12 null null null null
C null null null 10 null null
D null 13 null null null null
E null null 11 null null null
F null null null null 17 null
G null null null null null 20
Currently I'm showing the projects as series, and the months in the X axis.
The problem is: each project will only have value to one month, but a month can have values from several projects, so a common bar chart, with several projects, will have a bunch of small bars, because of the blank spaces of the null values.
Is there a way to hide these null columns?
Or a better way to show this data?
If the value of a "Project" only ever appears in one month, then the way to fix the spacing issue is to set the "isStacked" option to true.
Related
for the below raw query, I want to build Django ORM query
Select * from employee
WHERE (address_id is not null OR address_id<>'*')
AND (xyz_id is null OR xyz_id='*')
AND (abc_id is null OR abc_id='*')
So I have build ORM query as below
data = Employee.objects.filter(~Q(address_id="23") | Q(address_id__isnull=False),
Q(xyz_id__isnull=False) | Q(xyz_id='*'),
Q(abc_id__isnull=True) | Q(abc_id=‘*’))
and when i print the query, it is showing as below
SELECT "employee"."id", "employee"."xyz_id", "employee"."abc_id" FROM
"employee" WHERE ((NOT ("employee"."address_id" = 23 AND
"employee"."address_id" IS NOT NULL) OR "employee"."address_id" IS
NOT NULL) AND ("employee"."xyz_id" IS NOT NULL OR "employee"."xyz_id"
= *) AND ("employee"."abc_id" IS NULL OR "employee"."abc_id" = *))
my question is why Q object in Django is adding bolded line in above generated query ? which is not solving for above raw sql criteria.
i am using Django 2.2 version
Kindly advise
If you write Q(foo=bar), then an implicit constraint is that foo is not NULL, if you negate that however, it will write NOT (foo = bar) but if foo is NULL, then NOT (foo = bar) is NOT (NULL = bar) which is NULL, so this will be filtered out of the queryset. which would thus result in FALSE whereas for NULL, one would expect that this is TRUE.
To thus ensure that ~Q(…) is the full opposite of Q(…), it thus should add foo IS NOT NULL to the condition.
In this specific case however the query optimizer could probably indeed figure out that it is not necessary due to the address_id IS NOT NULL later in the query, but here apparently the optimizer does not eliminate that clause.
I have a column in Power Query
[Column1]
X
null
null
null
null
Y
null
null
null
in which I want to eliminate the bottom going up to "y" in this example,
leaving only the top portion.
[Column1]
X
null
null
null
null
I could do this by eliminating a specific number of rows, but I'd rather do it dynamically so that, no matter how long the data below Y gets, it will still cut off above Y, leaving only X and the data below X
I know that Table.Skip can do the same thing from the top going down, but this is more like a reverse of that process.
In Home ... Advanced Editor ... try using this, replacing Source with your prior step name
= Table.FirstN(Source, each [Column1]<>"Y")
In Power BI I have an M Query that tests for the value in a column equaling or not equaling to null.
When I add the statement for [Sale.Revenue] <> null I get an error however it works fine for the [UserRole.Name] = null it works fine. Tested just by removing the statement and adding it back.
We cannot convert the value null to type Logical.
This seems like it should work but just can't figure it out.
add_user_role_group = Table.AddColumn(
join_expand_sale,
"UserRole.Group1",
each (
if [UserRole.Name] = null and
[Sale.Revenue] <> null then
"Group1"
else if Text.Contains([UserRole.Name], "Manager") then
"Group2"
else
"Undefined"
)
)
I am sure it is something glaringly obvious :/ Thanks for your thoughts on this.
One of your rows has a null value for both UserRole.Name and Sale.Revenue. You need to check for that explicitly, and then add it to the "Undefined" group.
What happened is that the first condition fails because Sale.Revenue is null. The second condition calls Text.Contains, which returns null when [UserRole.Name] is null (Text.Contains returns a nullable logical value). null is not true or false, so you get the error.
After a such journey, finaly I found Text.Length !!
You can solve your problem like this:
if Text.Length([UserRole.Name]) = 0 and
Text.Length([Sale.Revenue]) > 0 then
I hope I have helped you.
Reference: Power Query M - Text.Length
Your issue is in the Text.Contains formula. You create an if statement that expects an expression that returns either true or false.
When the Text.Contains formula contains a null value, it returns 'null' as answer, and not true or false. You can adjust your code:
Text.Contains([UserRole.Name], "Manager")
To
Text.Contains([UserRole.Name]??"", "Manager")
The ?? is the COALESCE operator. In case it finds a null value, it now treats it as "". Instead of returning null it now returns true or false.
More on text functions in this article: https://gorilla.bi/power-query/text-functions/
Enjoy Power Query,
Rick
Hi guys My code looks like
iif(not isnull(ltrim(rtrim(a))) or not is_spaces(ltrim(rtrim(a))) or ltrim(rtrim(a))!='' or length(ltrim(rtrim(a)))!=0 or ltrim(rtrim(a))!=null or ltrim(rtrim(a))!='NULL'and not isnull(ltrim(rtrim(b))) or not is_spaces(ltrim(rtrim(b))) or ltrim(rtrim(b))!='' or length(ltrim(rtrim(b)))!=0 or ltrim(rtrim(b))!=null or ltrim(rtrim(b))!='NULL',null,ltrim(rtrim(a))).
If both a and b are not null then i have to make a as null else pass the value of a as it is. But my logic is not working fine and I've checked with session logs by giving verbose data for expression transformation still my value of b which is [NULL] coming in session logs has been considered as not null . Can you please help me guys for giving exact statements to identify the null values properly.
I've tried with is_spaces, empty strings.length!=0 options. But still null values are considered as an actual values which is wrong.
I think you need to group the conditions for a and b as shown below
IIF
(
(
NOT ISNULL(LTRIM(RTRIM(a)))
OR NOT IS_SPACES(LTRIM(RTRIM(a)))
OR LTRIM(RTRIM(a)) != ''
OR LENGTH(LTRIM(RTRIM(a))) != 0
OR LTRIM(RTRIM(a)) != NULL
OR LTRIM(RTRIM(a)) != 'NULL'
)
AND
(
NOT ISNULL(LTRIM(RTRIM(b)))
OR NOT IS_SPACES(LTRIM(RTRIM(b)))
OR LTRIM(RTRIM(b)) != ''
OR LENGTH(LTRIM(RTRIM(b))) != 0
OR LTRIM(RTRIM(b)) != null
OR LTRIM(RTRIM(b)) != 'NULL'
)
,NULL
,LTRIM(RTRIM(a))
)
Hope this helps.
NOTE: I have not optimized your checks for checking null conditions.
Given the following table:
Table: Comedians
=================
Id First Middle Last
--- ------- -------- -------
1 Bob NULL Sagat
2 Jerry Kal Seinfeld
I want to make the following prepared query:
SELECT * FROM Comedians WHERE Middle=?
work for all cases. It currently does not work for the case where I pass NULL via sqlite3_bind_null. I realize that the query to actually search for NULL values uses IS NULL, but that would mean that I cannot use the prepared query for all cases. I would actually have to change the query depending on the input, which largely defeats the purpose of the prepared query. How do I do this? Thanks!
You can use the IS operator instead of =.
SELECT * FROM Comedians WHERE Middle IS ?
Nothing matches = NULL. The only way to check that is with IS NULL.
You can do a variety of things, but the straight forward one is...
WHERE
middle = ?
OR (middle IS NULL and ? IS NULL)
If there is a value you know NEVER appears, you can change that to...
WHERE
COALESCE(middle, '-') = COALESCE(?, '-')
But you need a value that literally NEVER appears. Also, it obfuscates the use of indexes, but the OR version can often suck as well (I don't know how well SQLite treats it).
All things equal, I recommend the first version.
NULL is not a value, but an attribute of a field. Instead use
SELECT * FROM Comedians WHERE Middle IS NULL
If you want match everything on NULL
SELECT * FROM Comedians WHERE Middle=IfNull(?, Middle)
if want match none on NULL
SELECT * FROM Comedians WHERE Middle=IfNull(?, 'DUMMY'+Middle)
See this answer: https://stackoverflow.com/a/799406/30225