How do I add if isBlank keeps failing - powerbi

Current I have this and works well
CALCULATE(if(ISBLANK(PDR[Count test]),0,COUNTROWS(Pdr)))
How do I add a '0' or 'NA' if the field has no data. Thanks

Try:
COALESCE( COUNTROWS(Pdr), 0 )

Related

'LOOKUPVALUE' does not support comparing values of type Number with values of type True/False

I'm quite new in using DAX in PowerBi and I need to perform the following dax function:
Latest Detailed =
LOOKUPVALUE (
EXAM_REPORT[ACTUAL_EXAM_DATE],
EXAM_REPORT[CES EXAM.EXAM_TYPE_SR_KEY],
EXAM_REPORT[CES EXAM.EXAM_TYPE_SR_KEY] = 2,
EXAM_REPORT[CES EXAM.EXAM_SIGNOFF_DATE],
ISBLANK ( EXAM_REPORT[CES EXAM.EXAM_SIGNOFF_DATE] ) = FALSE,
EXAM_REPORT[ASSET_GUID],
[ASSET_GUID] = [ASSET_GUID]
)
Unfortunately I keep getting this error:
Function 'LOOKUPVALUE' does not support comparing values of type Number with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values.
I’ve tried converting everything to strings and also tried VALUE as well, but nothing changes.
Could you please help me? How can I do in a way that all the values share the same datatype?
LOOKUPVALUE has a different signature than what you are using:
LOOKUPVALUE(
<result_columnName>,
<search_columnName>,
<search_value>
[, <search2_columnName>, <search2_value>]…
[, <alternateResult>]
)
Your Code:
LOOKUPVALUE(
<result_columnName>,
<search_columnName>,
<search_columnName> = <search_value>
)
And FALSE must be FALSE(), but the condition is inappropriate anyway.

Get first non-empty cell in row

In Google Sheets, how do I get the value of the first non-empty cell in the row 17 starting at column C forwards?
I'm looking at a similar issue and found solutions similar to this, that might work for you:
=INDEX(C17:17,MATCH(TRUE,C17:17<>"",0))
As I understand it, MATCH will find the position of the first element in C17:17 that it's different to "" (exactly, hence the 0) and index will retrieve the value from that same range.
try:
=INDIRECT(ADDRESS(17, INDEX(MIN(IF(C17:17<>"", COLUMN(C17:17), )))))
I found another way that works, but not nearly as elegant as player0's.
=INDEX( FILTER( (SORT(TRANSPOSE(C17:17),TRANSPOSE(COLUMN(C17:17)),FALSE)) , NOT( ISBLANK( (SORT(TRANSPOSE(C17:17),TRANSPOSE(COLUMN(C17:17)),FALSE)) ) ) ) , ROWS( FILTER( (SORT(TRANSPOSE(C17:17),TRANSPOSE(COLUMN(C17:17)),FALSE)) , NOT( ISBLANK( (SORT(TRANSPOSE(C17:17),TRANSPOSE(COLUMN(C17:17)),FALSE)) ) ) ) ) )
I put this together from two other answers on SO, one on how to reverse the cells in a row, and one on finding the last non-empty cell in a column.
So this formula reverses C17:17, but leaves it as a column:
=(SORT(TRANSPOSE(C17:17),TRANSPOSE(COLUMN(C17:17)),FALSE))
And then this result is used as the range, when finding the last non-blank value in a column, which would be the first non-blank from the original row.
(From Get the last non-empty cell in a column in Google Sheets)
I replaced A:A in the following, with the formula from just above.
=INDEX( FILTER( A:A ; NOT( ISBLANK( A:A ) ) ) ; ROWS( FILTER( A:A ; NOT( ISBLANK( A:A ) ) ) ) )
The result is not very pretty but it worked.
Forced with computation speed.
The next formula is the most productive:
=MATCH(FALSE;MAP(5:5;LAMBDA(val;ISBLANK(val)));0)
Description:
Convert the analysed row to the array with “True” and “False” values.
If the cell is not empty -> True, else False. Then find the first “False” element in the array.
Function “ISBLANK” is used to check empty cells
NOT(ISBLANK(val)
Function “MAP” applies the “ISBALNK” to each cell in the row and returns an array.
MAP(5:5;LAMBDA(val;NOT(ISBLANK(val))))
MUTCH finds the index of the first non-empty cell

PowerBi - Weeknumber not in the correct order

I'm new to PowerBi and i'm running into the following problem:
Weeknum + year are not shown in the correct order. See the following screenshots:
I've concatenate weeknumber with year based on a column called "PublishDate"
This is my dax query for weeknum:
Weeknum = YEAR ( [PublishDate] ) & "" & WEEKNUM ( [PublishDate], 2 )
I do notice that 1 till 9 are not shown with a 0 infront of it. Could this be causing this?
I agree with getting the '0' in the right place. Once you change the data type from text to a number, if that '0' in't there, it will be out of order as well.
I prefer editing the query and changing the data type from the beginning:
Finding the column that needs a data type change and modifying it there:
[
You can change it from text to whole number.
The problem is that the values are being sorted in alphabetical order, because they are of datatype text. So yes, the fact that '9' does not have a '0' in front of it, does cause your problem. You can solve this by changing the format of the WEEKNUM function like this (also you do not need & "" &):
Weeknum = YEAR ( [PublishDate] ) & FORMAT(WEEKNUM ( [PublishDate], 2 ),"00")

Power Query M - We cannot convert the value null to type Logical

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

Handling null values in informatica flat files

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.