can't get SSRS 2008 IIF statement with DatePart to work - reporting-services

I'm getting an error when I use the statement below. I'm using an IIF statement to get the correct week number. The week numbers are different for 2016 than other years so my old expression is returning one week number later than it should -- the old: =DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.value).
what I have written but am getting an error and I cannot figure out what the problem is:
=IIF(=DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
“2016”,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))
basically, if the year of the field REQ_DATE is 2016, I want the WeekOfYear for REQ_DATE - 1; else just the WeekOfYear.
can anyone help me? thank you!

You don't have to use = for every function you call in an expression, use the = only once at the beginning of the whole expression.
Try:
=IIF(DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
"2016",DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))

Related

Migrating Measures and calculated columns from Tableau to PowerBi

Stuck at a specific measure calculation which looks like this in tableau
1.) zn(COUNTD(if not isnull([Order_number]) then [Order_number] END)).
I tried using isblank dax function but it is not working as i expected it to be.
How will the same measure be written in Powerbi using DAX?
Problem 2
Simultaneously, not able to get the output for a particular calculated column in powerbi for which the tableau query to derive that particular column looks like this:
2.) zn(IF CONTAINS([Record Type],"High") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '08520' THEN 7 ELSEIF CONTAINS([Record Type],"Junior") and datename('weekday',[Activity Date]) = 'Sunday' AND [Location] = '8520' THEN 7 end
I re created the above by Creating a custom column named it as Day Name deriving day name from the date column and Wrote an equivalent query in Powerbi query editor to create a custom column, query mentioned below. Even though there is no syntax error, it is giving 0 for all the rows in that particular calculated column.
slots= if([RECORD_TYPE]="high" and [Day Name]="Sunday" and [LOCATION]=08520) then 7 else
if([RECORD_TYPE]="Outbound" and [Day Name]="Sunday" and [LOCATION]=3109) then 7 else 0
Any kind of lead or help will be much appreciated.
Thanks in advance
For 1st problem:
zn(COUNTD(if not isnull([Order_number]) then [Order_number] END))
So, If i break this query basically, zn is a function used in tableau to convert all the null values to zero and as countd implies to the entire if statement above.
I was able to write an equivalent dax query for it mentioned below, if anyone out there can tell me or verify if it is correct or not, I'll be really thankful.
IF(ISBLANK(DISTINCTCOUNT(Order_table[ORDER_NUMBER])),0,DISTINCTCOUNT(Order_table[ORDER_NUMBER]))
As far as the second problem goes, im not able to find a solution to it and the value for that column for all the rows stands at 0 as I'm writing this answer to 1st problem. Any kind of help or lead will be much appreciated.
Thanks

DateDiff function in SSRS (report server) gives error?

Im trying to find the days gap between two dates using DateDiff function.
I have 2 datasets defined. If companycode is 'AB' then from one dataset else from another dataset I retrieve data.
Here is my expression. When I change to preview mode, it shows redmark to the first First(Fields!PeriodFrom.Value line. Why? (after generating report that field shows #Error
What Im doing wrong here?
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",First(Fields!PeriodFrom.Value, "ABReportData"), First(Fields!PeriodTo.Value, "ABReportData")),
DateDiff("d",First(Fields!PeriodFrom.Value, "XYReportData"), First(Fields!PeriodTo.Value, "XYReportData")))
I think there are two possible scenarios. First one is the expression
=First(Fields!PeriodFrom.Value, "ABReportData")
doesnt return a value. Add a column with this expression and check if you get a value.
If the value is correct, make sure that the DateDiff() function gets a date:
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "ABReportData")),
CDate(First(Fields!PeriodTo.Value, "ABReportData"))
),
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "XYReportData")),
CDate(First(Fields!PeriodTo.Value, "XYReportData"))
)
)

expression in split component in SSIS giving error

I am trying to implement conditional split component in my SSIS package. I need to split the records based on the year. I need to extract data for the last 5 years and need to split it before i dump it to the destination
periodenddate is datetime field. I need to extract the year part from that field and compare it against the actual year as mentioned in the expression. I am getting an error for invalid expression. Could somebody tell me where am i going wrong
The expression i am using is for eg
periodEndDate == YEAR(GETDATE())
Please find the error attached
Second error
Third error
If you want the year number from one year ago, you need to use:
YEAR([periodenddate]) = YEAR(GETDATE()) - 1
YEAR([periodenddate]) = YEAR(GETDATE()) - 2
etc.
Having the "-1" inside the parentheses for the Year() function will give you the wrong answer at the very least.
Note that you got different errors with each version of your code:
The first image shows a failure to find a field due to SSIS being case sensitive
The second image shows a failure due to comparing a datetimestamp to an integer
The third image shows an error with the expression "GETDATE() - 1", which is on a different conditional expression component than the first two images.

MySQL Crystal query, how do I select CurrentDate() field and blank dates?

I'm new to SQL. I'm trying to select records less than the current date which is working however we also have entries where the date field is blank which I need to include in the report. I need to be able to see both the current date AND dates that are blank. Any way to accomplish this?
{LOAN1.XLN-PROMDATE} < CurrentDate()
The correct syntax in crystal would be isnull ({datefield}) or {date field} < {?parameter} isnull is not comparable to a value - null means the absence of data, which is not comparable. Hope that helps

Comparing todays date against first day of the week

I am trying to set a default parameter value in SSRS report. I want to test the current date to see if it equals the first day of the week (in my case Monday). If it is the first day of week, then I want the default value to be current date minus 2 days, if it is not the first day of the week then I want the default value to be current date minus 1 day.
I seem to have a syntax problem but it doesn't tell me where. My parameters are StartDate and EndDate.
this is what I've tried:
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today(),DateAdd("d",-1,today())
this is the generic error I get:
The value expression for the report parameter 'StartDate' contains eror:[BC30201] Expression expected.
Where am I going wrong?
You are trying to use Sql syntax in a SSRS VBA expression. SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum.
So your expression needs to use VBA syntax:
=IIF(Weekday(Today, FirstDayOfWeek.Monday) = 1, DateAdd(DateInterval.Day, -2, Today), DateAdd(DateInterval.Day, , -1, Today))
It appears that you are missing a closing parentheses after the first logical part of the if statement and another to close the statement.
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today()),DateAdd("d",-1,today()))