DAX Syntax - if versus switch - dax

Need help with the correct syntax. I need to determine based on 3 columns (Year, Years of Service, Terminate) if the years of service fall between the following criteria or the Terminate column has a date.
IF(["#YearsofService"]=>2,"2+ Years" else "Less than 2 Years") else Terminate(has a date) is not null. This will be for an new column displaying the criteria text.
also tried Switch function.
=SWITCH(TRUE()
[#"#YearsofService"] >=2,"2 + Years" & [#"#YearsofService"] <2, "Less Than 2 Years",
isblank([Term Date]), "Termed"
)
also tried:
IF(ISBLANK([Term Date])=false, "Termed",IF([#"#YearsofService"] >=2,"2 + Years","Less Than 2 Years"))
but does not like the If portion of statement

I think SWITCH TRUE would be the best solution for this sort of multi-test requirement. The sequence of tests after the TRUE is critical - DAX will stop evaluating after the first TRUE result is struck. So here's my attempt:
=SWITCH(TRUE()
, NOT(ISBLANK([Term Date])), "Termed"
, [#YearsofService] >=2,"2 + Years"
, [#YearsofService] <2, "Less Than 2 Years"
)

In your example you are only using two of the mentioned columns (Years of Service and Terminate). I guess the statement should look like this:
Result = IF(ISBLANK([Term Date]);IF([#"#YearsofService"]<2;"Less than 2 years";"More than 2 years");"Termed")

Related

Years of Service Anniversary formula - Cognos Analytics - Costpoint 8.0.0

this one has been bugging me for a few weeks... I'm trying to write a formula in Cognos Analytics (costpoint) that returns if someone is hitting a new years of service milestone in the actual month.
returning a simple "true/false" or "yes/no" is perfect
essentially it's just if their years of service fall between multiple date ranges (ex: i want a return value of "yes" for someone currently at 4.95 years of service since they would hit their 5 years within the coming month)
years of service are in number format in column "A" in excel and in column [years of service] in costpoint (cognos) (ex: 9.154, 4.982, 24.995 ...)
i got an Excel version to work seen below:
=IF(OR(AND(A1>4.91,A1<=5),(AND(A1>9.91,A1<=10)),(AND(A1>14.91,A1<=15)),(AND(A1>19.91,A1<=20)),(AND(A1>24.91,A1<=25)),(AND(A1>29.91,A1<=30))),"yes","no")
i'm still just getting familiar with Cognos(costpoint) syntax, so i tried to write it as seen below:
if(or(and([Years of Service]>4.91,[Years of Service]<5),(and([Years of Service]>14.91,[Years of Service]<15)))then ('yes') else ('null')
without any luck...
anyone want to take a crack at it?? :)
In the absence of start dates, which would be easier, and handling the more general case (What if they are approaching 45 years of service?):
case
when MOD(MOD([Years Of Service], 5) + 1, 5) > 0.91
and MOD(MOD([Years Of Service], 5) + 1, 5) <= 1
then 'yes'
else 'no'
end
To see who reaches a "years of service" value that is a 5-year milestone next month, create a filter:
mod(
_months_between (
_first_of_month (
_add_months (current_date, 1)
),
_first_of_month ([StartDate])
),
60
) = 0
But if you have service start dates, you can use dates calculations to see who reaches a 5-year milestone next month:
mod(
_months_between (
_first_of_month (
_add_months (current_date, 1)
),
_first_of_month ([StartDate])
),
60
)
Look at the various case functions and try them for your expression.
I don't think you need a start date, you could just focus on the decimal portion of the Years of service field. You know that if the decimal portion is equal to or above ).9166 then the years of service is in the final month.
if ([YOS]-cast([YOS],integer)>=0.9166)
then
('Yes')
else
('No')
If you want to figure a major milestone year such as 5,10,15 then you can take the expression further.
if mod(
if ([YOS]-cast([YOS],integer)>=0.9166)
then
(cast([YOS],integer)+1)
else
(cast([YOS],integer)),5=0)
then ('Milestone Year')
else ('Keep on Working!')
Hopefully the above helps!

Expressions that yield variant data-type cannot be used to define calculated columns

Team,
I'm trying to get the last 12 months of financials, using the days as my base, and am getting the the expression yield error. I think it's because they aren't text, but calculated columns.
What is best to add to this? I tried 'value' and that didn't work. I think the isnonblank may work.. or is blank? As there will be blanks returned.
Here's the formula:
Last 12 Mn Amt = (if('LSI DP_JP_HistorySummaryBySiteMaster'[Z - Days]>=-365,'LSI DP_JP_HistorySummaryBySiteMaster'[Z Total Revenue + Rent Revenue],""))
The problem is that the TRUE result returns a different data type than the FALSE result.
Try replacing "" with blank or zero.
Last 12 Mn Amt =
IF (
'LSI DP_JP_HistorySummaryBySiteMaster'[Z - Days] >= -365,
'LSI DP_JP_HistorySummaryBySiteMaster'[Z Total Revenue + Rent Revenue],
BLANK ()
)
Note: Omitting the 3rd argument entirely returns BLANK() as the default behavior.

syntax help for comparison logic

I am trying to find out the loss of portfolios from the current month to the prior month.
What I want to see is what missing, basically when we compare the two months together I want to display what is not matching between the two
I have put this expression.
If([portfolio_code Current ]=[portfolio_code_Prior])
Then(Count([portfolio_code Current ])
Else(0)
I am not sure my if syntax is incorrect I just wanted to give an example
any insights?
[enter image description here]
Assuming there is one portfolio per row the count of portfolios that were in last month and not this month is...
total(
If ( [portfolio_code Current ] <> [portfolio_code_Prior] && [portfolio_code_Prior] is not null)
Then ( 1 )
Else ( 0 )
)
or
total(
case
when [portfolio_code Current ] <> [portfolio_code_Prior] and
[portfolio_code_Prior] is not null
then 1
else 0
end
)
If you want to see how many were "lost" from this month to last month (how many were added form last month to this month) you would need to reverse the logic.
If you want to see how many more or less, that is much simpler:
count(distinct [portfolio_code_Prior]) -
count(distinct [portfolio_code Current ])
If you want 0 when they don't match otherwise the portfolio code, then your logic looks okay.
If you want to ONLY see the rows that do not match then add a detail filter for the custom data item, let's call it compare, like this:
[Compare] <> 0
as far as counting, you can just select the column and use count (or count distinct) depending on what you want.

SUMIF with date range for specific column

I've been trying to find an answer for this, but haven't succeeded - I need to sum a column for a specified date range, as long as my rowname matches the reference sheet's column name.
i.e
Reference_Sheet
Date John Matt
07/01/19 1 2
07/02/19 1 2
07/03/19 2 1
07/04/19 1 1
07/05/19 3 3
07/06/19 1 2
07/07/19 1 1
07/08/19 5 9
07/09/19 9 2
Sheet1
A B
1 07/01
2 07/07
3 Week1
4 John 10
5 Matt 12
Have to work in google sheets, and I tried using SUMPRODUCT which told me I can't multiply texts and I tried SUMIFS which let me know I can't have different array arguments - failed efforts were similar to below,
=SUMIFS('Reference_Sheet'!B2:AO1000,'Reference_Sheet'!A1:AO1,"=A4",'Reference_Sheet'!A2:A1000,">=B1",'Reference_Sheet'!A2:A1000,"<=B2")
=SUMPRODUCT(('Reference_Sheet'!$A$2:$AO$1000)*('Reference_Sheet'!$A$2:$A$1000>=B$1)*('Reference_Sheet'!$A$2:$A$1000<=B$2)*('Reference_Sheet'!$A$1:$AO$1=$A4))
This might work:
=sumifs(indirect("Reference_Sheet!"&address(2,match(A4,Reference_Sheet!A$1:AO$1,0))&":"&address(100,match(A4,Reference_Sheet!A$1:AO$1,0))),Reference_Sheet!A$2:A$100,">="&B$1,Reference_Sheet!A$2:A$100,"<="&B$2)
But you'll need to specify how many rows down you need it to go. In my formula, it looks down till 100 rows.
To change the number of rows, you need to change the number in three places:
&address(100
Reference_Sheet!A$2:A$100," ... in two places
To briefly explain what is going on:
look for the person's name in row 1 using match
Use address and indirect to build the address of cells to add
and then sumIfs() based on dates.
alternative:
=SUMPRODUCT(QUERY(TRANSPOSE(QUERY($A:$D,
"where A >= date '"&TEXT(F$1, "yyyy-mm-dd")&"'
and A <= date '"&TEXT(F$2, "yyyy-mm-dd")&"'", 1)),
"where Col1 = '"&$E4&"'", 0))

Oracle DateAdd() of 2 different columns

I'm trying to figure out a DateAdd() equivalent in Oracle that is actually the difference in seconds between 2 columns in the same table:
SELECT
DISTINCT p.packet_id,
p.launch_dt,
r.route_duration,
s.completion_date,
DATEADD(SS, r.route_duration, p.launch_dt) AS tempDate
FROM
tdc_arc_apprpkt_def p
JOIN tdc_arc_inpr_route_def r
ON p.packet_id = r.packet_id
JOIN tdc_arc_inpr_route_step_detai s
ON p.packet_id = s.packet_id
AND s.completion_date > DATEADD(SS, r.route_duration, p.launch_dt)
Any help would be greatly appreciated!
In addition to being able to do date arithmetic using fractions of days as Tony demonstrates, assuming you are using 9i or later, you can also use interval functions (or, even better, define the ROUTE_DURATION column as an interval) and add intervals to dates. In your case, you can do
p.launch_dt + numtodsinterval( r.route_duration, 'SECOND' )
to add route_duration seconds to launch_dt.
If you were to define the route_duration column as an INTERVAL DAY TO SECOND rather than a NUMBER, you could simply add it to a date
p.launch_dt + r.route_duration
If I understand you correctly, you want to add r.route_duration seconds to p.launch_dt? In that case the expression is:
p.launch_dt + (r.route_duration/24/60/60)
Oracle DATE arithmetic works in days, so the divisions by 24, 60 and 60 convert the route_duration value from seconds to days.

Resources