Multiple If statements Cognos RS 10 - if-statement

In Cognos RS 10, I am trying to create multiple if statements but the report fails. The report works when I do not have this in as an expression.
I want to create a field that shows days between RUN date and Received date when Status Classification = 'Open' and when it = 'Pend'.
I want to create a field that shows days between CLOSED date and Received date when Status Classification = 'Closed'
Can someone offer some help? The expression validates but the report fails. Any help is greatly appreciated.
This is what I'm using:
**If ([CS].[Status Classification] = 'Open') THEN
(_days_between ([Run Date] , [CS].[Received Date]))
else IF ([CS].[Status Classification] = 'Pend') THEN
(_days_between ([Run Date] , [CS].[Received Date]))
else IF ([CS].[Status Classification] = 'Closed') THEN
(_days_between([CS].[Closed Date Time] , [CS].[Received Date]))
ELSE
null**

You need to use brackets around each if, so it'll be like:
IF (condition) THEN (expression)
ELSE
(
IF (condition) THEN (expression)
ELSE (expression)
)
or use case expression.
case (expression)
when () then ()
else ()
end

Related

Multiple IF conditions in PowerBI to see if the date falls within Date Range

I need to create a condition where my start date for last year is 3/14/2021 and end date is 11/14/2021 and For this year 3/13/2021 and end date is 11/13/2021. What ever the date falls with in this range should be true else False
I have list of dates where i need to see if the dates fall within the above mentioned range
List of dates
2/6/2021
6/6/2021
1/3/2022
9/8/2022
11/19/2022
I need a result as
MM/DD/YYYY
2/6/2021 - False
6/6/2021 - True
1/3/2022 - False
9/8/2022 - True
11/19/2022 - False
In DAX you should try something like this:
IF(
(SELECTEDVALUE() >= "3/14/2021" AND SELECTEDVALUE() <= "11/14/2021")
|| (SELECTEDVALUE() >= "3/13/2022" AND SELECTEDVALUE() <= "11/13/2022"),
SELECTEDVALUE(),
BLANK()
)
This formula will work on report panel. Let me know if you want to use in on data panel - I will correct my answer.
9/8/2022 is not in the range 3/13/2021 through 11/13/2021, so no idea why that should be true, but in general the format in M/PowerQuery is below, assuming the test column is named date
#"Added Custom" = Table.AddColumn(#"PriorStepNameGoesHere", "CheckDate", each if [date]>=#date(2021,3,13) and [date]<=#date(2021,11,13) then true else false)
or potentially two date ranges
#"Added Custom" = Table.AddColumn(#"PriorStepNameGoesHere", "CheckDate", each
if [date]>=#date(2021,3,14) and [date]<=#date(2021,11,14) then true
else if [date]>=#date(2022,3,13) and [date]<=#date(2022,11,13) then true
else false)

PowerBI DAX - IF with AND / OR

I am sure this is a simple question but I have tried a few versions found on here and can't seem to get the syntax right. Have also tried using SWITCH function and similarly encountered errors with the code.
Essentially, I want to mark each record with an 'Overdue' indicator based on the following logic. Within my data, some records have a Target Date populated but many are null. For the records that are null, I want to use the Action Due Date to determine if it is overdue or not.
IF 'STATUS' is not 'CLOSED' AND 'TARGET DATE' less than today = Overdue
OR
IF 'STATUS' is not 'CLOSED' AND 'ACTION DUE DATE' less than today = Overdue
ELSE Not Overdue
The DAX I am trying to write is like this :
Overdue =
IF('Table'[Status] <>"Closed" && 'Table'[Target Date]<Today(), "Overdue", OR(
IF('Table'[Status] <>"Closed" && 'Table'[Action Due Date]<Today(), "Overdue",
"Not Overdue")))
Sorry for the dumb question, really struggling with the progression to DAX from Excel.
Try this then
IF(
OR(
'Table'[Status] <>"Closed" && 'Table'[Target Date]<Today()
,'Table'[Status] <>"Closed" && 'Table'[Action Due Date]<Today()
)
,"Overdue"
,"Not Overdue"
)

How to add WHERE condition for last 12 months in DAX query

EVALUATE
FILTER
(
SUMMARIZE (
'Product_Category',
'Product_Category'[id],
'Product_Category'[Sale-Date],
'Product_Category'[Store],
'Product_Category'[Description]
),
'Product_Category'[Acronym] = "Test Product"
)
ORDER BY 'Product_Category'[Sale-Date]
I have the above sample DAX expression to get product sales data. I want to add some sort of a WHERE clause such that only records where the "[Sale-Date]" is in the last 12 months are returned.
I cant seem to figure out how to add that condition, any one please help.
SQL WHERE is FILTER in Dax. You already are using one filter criteria:
'Product_Category'[Acronym] = "Test Product"
To expand what you have:
EVALUATE
FILTER
(
SUMMARIZE (
'Product_Category',
'Product_Category'[id],
'Product_Category'[Sale-Date],
'Product_Category'[Store],
'Product_Category'[Description]
),
'Product_Category'[Acronym] = "Test Product" &&
'Product_Category'[Sale-Date] >= DATE(YEAR(NOW())-1, MONTH(NOW()), DAY(NOW()))
)
ORDER BY 'Product_Category'[Sale-Date]

Google Sheet Formula for finding an element across multiple tabs

I`m trying to populate values in column F, "Product Sold Date" in "TABLES" tab
Basically... the logic is as follows:
1) If Column C (Product Status) = "Paused", then return "Paused"
2) If Product start date = NULL or Product end date = NULL, then return NULL
3) If Product start date < today`s date, then return "No Data"
4) If Product start date >= today`s date, return "Upcoming"
5) If product End date <= today`s date, return "Ended"
6) If product start date <= today`s date, return "In Market"
7) If the condition does not belong to any of the above cases, then return the actual Product launch dates
Below is the link to the sample data I`m working on..
I`m pasting the link itself, becaues there are multiple tabs included
https://docs.google.com/spreadsheets/d/120rHOt8Pa_PdMKPgLkSYOKTO2Cv1hBH6PpTrg7FfJLk/edit?usp=sharing
Ultimately, I need to populate the actual "Product Launch Date" by scanning data in each tab
I tried using nested if statements with combination of Index Match.
But I`m totally lost in case of multiple tabs
Can anyone please provide suggestion on this?
Should we think about using query statements instead in this case?
Sidenote: The returned values will be mix of dates and character
[In market/ Ended/ Upcoming/ No Data/ NULL/ Paused/ Actual Date]
=ARRAYFORMULA(
IF(C2:C="Paused", C2:C,
IF((A2:A="")+(B2:B=""), ,
IF(A2:A >= TODAY(), "Upcoming",
IF(B2:B <= TODAY(), "Ended",
IF(A2:A = TODAY(), "In Market",
IF(E2:E<>"", IFERROR(VLOOKUP(D2:D&E2:E,
{'Eaton Centre'!A2:A &"Eaton Centre", 'Eaton Centre'!B2:B;
'Yorkdale Mall'!A2:A&"Yorkdale Mall", 'Yorkdale Mall'!B2:B;
'Vaughan Mills'!A2:A&"Vaughan Mills", 'Vaughan Mills'!B2:B}, 2, 0)), )))))))
Your formula would be
=IF(C2="Paused",C2,if(OR(A2="",B2=""),"",IF(A2<TODAY(),"No Data",IF(A2>=TODAY(),"Upcoming",IF(B2<=TODAY(),"Ended",IF(A2<=TODAY(),"In Market","Actual Product Launch dates"))))))
In the above formula, you should be using a Query formula in place of "Actual Product Launch dates", to extract the actual date.
But the points 3 & 6 don't make any sense. The 6th condtion should be If product start date = todays date, return "In Market"

OLE DB or ODBC Error: We cannot convert the value null to type Logical

I am calculating following calculated column in query editor:
End Date =
if [Date_1] <> null
then [Date_1]
else if [Date_2]<>null
then [Date_2]
else DateTime.Date(DateTime.LocalNow())
Based on this column, the following table is calculated:
Resident Payer Dates =
SELECTCOLUMNS (
GENERATE (
'Table1',
FILTER (
ALLNOBLANKROW ( Dates[Date] ),
Dates[Date] >= 'Table1'[Start Date]
&& Dates[Date] <= 'Table1'[End Date]
)
),
"Id", 'Table1'[Id],
"Date", Dates[Date]
)
Everything is working fine till here.
However, for some reason, I need to change the End Date column with the following formula:
End Date =
if [Date_1] <> null
then Date.AddDays([Date_1], -1)
else if [Date_2]<>null
then Date.AddDays([Date_2],-1)
else DateTime.Date(DateTime.LocalNow())
However, when I try to apply the changes, I am getting the following error:
I am totally clueless about why we are running in this error with a simple change like above, as the change is not producing any null values.
Any help and guidance would be appreciated.
For anyone who faces such issue in future:
Here, the query editor shows no errors and the evaluation is completed till the last step successfully. However, when you try to apply the changes, the error mentioned above is encountered.
With a lot of searches, I figured out that the column got corrupted, for reasons being still unknown.
To solve this, all you have to do is to remove the step/column completely and recreate it, the error will go away.