SSRS and SSAS are supported by VB

Source: Internet
Author: User
Tags mathematical functions

SSRS and SSAS are supported by VB, and custom code is actually only supported by VB, or other languages can be encoded into DLLs and then use. The following is the official VB function library, basically can be used, preserved and duly completed.

Https://msdn.microsoft.com/en-us/library/ms157328.aspx

Https://msdn.microsoft.com/library/c157t28f.aspx

In fact, we generally use in SSRS and SSAS are more than a few character functions, date functions, judgment function, if there is a very complex processing, it is recommended to do better in the data. The following is an example of an official function.

Visual Basic functions

You can use Visual Basic functions to manipulate the data that is displayed in a text box, or to manipulate data that is used in parameters, properties, or other areas of the report. This section provides examples of some of these functions. For more information, see Visual Basic Runtime Library members (Visual Basic run-time libraries).

The. NET Framework provides many custom formatting options, such as a specific date format. For more information, see Formatting Types on MSDN.

Mathematical functions
    • The Round function can be used to round a number to the nearest integer. The following expression rounds 1.3 to 1:

      = Round(1.3)

      You can also write an expression to round a value to a multiple that you specify, similar to the mround function in Excel. multiply the number by a factor that generates an integer, round the numbers, and then divide by the same factor. For example, to round 1.3 to the nearest multiple of. 2 (1.4), use the following expression:

      = Round(1.3*5)/5
Date function
  • The today function can provide the current date. This expression can be used in a text box to display dates on a report, or in parameters to filter data based on the current date.

    =Today()
  • To provide a date range based on a single parameter, you can use the DateAdd function. The following expression provides a date that is six months after the date of the parameter named startdate .

    =DateAdd(DateInterval.Month, 6, Parameters!StartDate.Value)
  • The Year function can display the years of a particular date. You can use this expression to group dates together, or to display the year as a label for a set of dates. This expression can provide a set of years for a given sales order date. the Month function and other functions are also available for date operations. For more information, see your Visual Basic documentation.

    =Year(Fields!OrderDate.Value)
  • You can combine functions in an expression to customize the format. The following expression changes the date format of "month-day-year" to "month-week-week number". For example, change "12/23/2009" to "December Week 3":

    =Format(Fields!MyDate.Value, "MMMM") & " Week " & (Int(DateDiff("d", DateSerial(Year(Fields!MyDate.Value), Month(Fields!MyDate.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString

    When this expression is used as a calculated field in a dataset, you can use the expression on the chart to aggregate the values by the week of the month.

  • The following expression sets the format of the Sellstartdate value to Mmm-yy. The sellstartdate field is a datetime data type.

    =FORMAT(Fields!SellStartDate.Value, "MMM-yy")
  • The following expression sets the format of the Sellstartdate value to dd/mm/yyyy. The sellstartdate field is a datetime data type.

    =FORMAT(Fields!SellStartDate.Value, "dd/MM/yyyy")
  • The CDate function converts a value to a date. The now function returns a date value that contains the current date and time, based on your system. DateDiff Returns a Long value that specifies the number of time intervals between two date values.

    The following example shows the start date for the current year

    =DateAdd(DateInterval.Year,DateDiff(DateInterval.Year,CDate("01/01/1900"),Now()),CDate("01/01/1900"))
  • The following example shows the start date based on the previous one months of the current month.

    =DateAdd(DateInterval.Month,DateDiff(DateInterval.Month,CDate("01/01/1900"),Now())-1,CDate("01/01/1900"))
  • The following expression generates a gap year between Sellstartdate and Lastreceiptdate. These fields are within two different datasets, namely DataSet1 and DataSet2. The first function (Report Builder and SSRS) is an aggregate function that returns the Sellstartdate value in DataSet1 and the first value lastreceiptdate in DataSet2.

    =DATEDIFF(“yyyy”, First(Fields!SellStartDate.Value, "DataSet1"), First(Fields!LastReceiptDate.Value, "DataSet2"))
  • The DatePart function returns an integer value that contains the specified component for the given date value. The following expression returns the year of the first value of sellstartdate in DataSet1. Specifies that the dataset is scoped because there are multiple datasets in the report.

    =Datepart("yyyy", First(Fields!SellStartDate.Value, "DataSet1"))
  • The DateSerial function returns a Date value that represents the specified year, month, and day, with the time information set to midnight. The following example shows the end date based on the last one months of the current month.

    =DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)
  • The following expression displays different dates based on the value of the date parameter selected by the user.

Example description

Example
Yesterday

=dateserial (Year (parameters! Todaysdate.value), Month (parameters! Todaysdate.value), Day (parameters! Todaysdate.value)-1)

Two days ago

=dateserial (Year (parameters! Todaysdate.value), Month (parameters! Todaysdate.value), Day (parameters! Todaysdate.value)-2)

One months ago

=dateserial (Year (parameters! Todaysdate.value), Month (parameters! Todaysdate.value) -1,day (parameters! Todaysdate.value))

Two months ago

=dateserial (Year (parameters! Todaysdate.value), Month (parameters! Todaysdate.value) -2,day (parameters! Todaysdate.value))

A year ago

=dateserial (Year (parameters! Todaysdate.value) -1,month (parameters! Todaysdate.value), Day (parameters! Todaysdate.value))

Two years ago.

=dateserial (Year (parameters! Todaysdate.value) -2,month (parameters! Todaysdate.value), Day (parameters! Todaysdate.value))

String functions
  • Use the concatenation operator and the Visual Basic constants to group multiple fields together. The following expression returns two fields, each in a different row of the same text box:

  • Use the format function to format dates and numbers in a string. startdate and EndDate parameters in a long date format:

     =format (parameters! StartDate.Value, "D") & "Through" & Format (parameters! Enddate.value, "D")  

    format property of the text box to apply the formatting. You should not use the Format function in a text box.

  • right , Len , and InStr functions are useful for returning substrings, such as DOMAIN \ username is clipped to the user name. The following expression returns a string part to the right of the backslash (\) character from a parameter named User :

     =right (parameters! User.value, Len (parameters! User.value)-InStr (parameters! User.value, "\"))  

    The following expression uses the members of the. NET Framework systemstring class instead of the Visual Basic functions. You can get the same value as the previous expression:

     =parameters! User.Value.Substring (parameters! User.Value.IndexOf ("\") +1, parameters! user.value.length-parameters! User.Value.IndexOf ("\")-1)  
  • Join function to concatenate the selected values of the parameter myselection into a single string that can be set as an expression of the text box value in a report item:

     = Join (parameters! Myselection.value)  

     = "Report for" & JOIN (parameters! Myselection.value, "&")  
  • The Regex function in the. NET Framework System.Text.RegularExpressions is useful for changing the format of existing strings, such as formatting phone numbers. The following expression uses the Replace function to change the format of the 10-digit phone number in a field from "nnn-nnn-nnnn" to "(nnn) nnn -nnnn":

    =System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")
    Attention

    Verify fields! The value of Phone.value has no extra spaces and is of type String.

Find
    • By specifying a key field, you can use the Lookup function to retrieve values from a dataset for a one-to-one relationship, such as a key-value pair. The following expression displays the product name from the dataset ("Product") by providing a product identifier for the match:

      =Lookup(Fields!PID.Value, Fields!ProductID.Value, Fields.ProductName.Value, "Product")
LookupSet
    • By specifying a key field, you can use the LookupSet function to retrieve a set of values from a dataset for a one-to-many relationship. For example, a person can have more than one phone number. In the following example, it is assumed that the dataset phonelist contains a person identifier and phone number in each row. an array of LookupSet return values. The following expression merges the return value into a single string and displays a list of phone numbers for the person specified by ContactID:

      =Join(LookupSet(Fields!ContactID.Value, Fields!PersonID.Value, Fields!PhoneNumber.Value, "PhoneList"),",")
Conversion functions

You can use Visual Basic functions to convert a field from one data type to another with a different data type. conversion functions can be used to convert the default data type of a field to the data type needed for the calculation or to combine text.

    • The following expression converts the constant 500 to a decimal type to compare it to the Transact-SQL Money data type in the filter Expression Value field.

      =CDec(500)
    • The following expression displays the number of values selected for the multivalued parameter myselection .

      =CStr(Parameters!MySelection.Count)
Decision function
  • The Iif function returns one of two values based on the evaluated result (True or False) of the expression. The following expression uses the Iif function to return a Boolean value of Truewhen the value of LineTotal exceeds 100. Otherwise, it will return False:

    =IIF(Fields!LineTotal.Value > 100, True, False)
  • Using multiple iif functions (also known as "nested IIF") can return one of three values based on the value of Pctcomplete. The following expression can be placed in the fill color of a text box to change the background color based on the value in the text box.

    =IIF(Fields!PctComplete.Value >= 10, "Green", IIF(Fields!PctComplete.Value >= 1, "Blue", "Red"))

    A value greater than or equal to 10 o'clock displays a green background with a blue background between 1 and 9, and less than 1 o'clock, which shows a red background.

  • There is another way to implement the same function, which is to use the Switch function. The Switch function is useful if you want to test three or more conditions. The Switch function returns a value associated with the first expression that evaluates to True in the sequence:

    =Switch(Fields!PctComplete.Value >= 10, "Green", Fields!PctComplete.Value >= 1, "Blue", Fields!PctComplete.Value = 1, "Yellow", Fields!PctComplete.Value <= 0, "Red",)

    A value greater than or equal to 10 o'clock displays a green background, a blue background between 1 and 9, a yellow background at 1 o'clock, or less than or equal to 0 o'clock, which shows a red background.

  • Tests the value of the importantdate field, returns "Red" if the value is greater than one week, or returns "Blue". This expression can be used to control the Color property of a text box in a report item:

    =IIF(DateDiff("d",Fields!ImportantDate.Value, Now())>7,"Red","Blue")
  • Tests the value of the phonenumber field, returns "No value" if null(Nothing in Visual Basic), or returns the phone number value. This expression can be used to control the value of a text box in a report item.

    =IIF(Fields!PhoneNumber.Value Is Nothing,"No Value",Fields!PhoneNumber.Value)
  • Test the value of the Department field and return the subreport name or null(Nothing in Visual Basic ). This expression can be used for conditional drillthrough subreports.

    =IIF(Fields!Department.Value = "Development", "EmployeeReport", Nothing)
  • Tests whether the field value is empty. This expression can be used to control the Hidden property of an image report item. in the following example, the image specified by the field [LargePhoto] is displayed only if the field value is not empty.

    =IIF(IsNothing(Fields!LargePhoto.Value),True,False)
  • The MonthName function returns a string value that contains the name of the specified month. The following example displays NA in the Month field (when the field contains a value of 0 o'clock).

    IIF(Fields!Month.Value=0,"NA",MonthName(IIF(Fields!Month.Value=0,1,Fields!Month.Value)))
Report functions

In an expression, you can add a reference to an additional report function that uses data from the report. This section provides an example of two of these functions. For more information about report functions and examples, see aggregate function references (Report Builder and SSRS).

Sum
    • The sum function can sum the values in a group or data region. This function is useful in group headers or at the end of the group. The following expression shows the sum of the data in the Order group or data region:

      =Sum(Fields!LineTotal.Value, "Order")
    • You can also use the Sum function for conditional aggregation calculations. For example, if the dataset contains a field named state whose possible values are not Started, Started, finished, the total number of aggregations for the finished value will be calculated only if the following expression is placed in the group header.

      =Sum(IIF(Fields!State.Value = "Finished", 1, 0))
RowNumber
    • The RowNumber function, if used in a text box within a data region, displays the line number of each instance in the text box where the expression is located. This function can be used to number each row in a table. It can also be used in more complex situations, such as inserting page breaks based on the number of rows. For more information, see page breaks in this topic.

      The scope specified for RowNumber controls when the re-count begins. The Nothing keyword indicates that the function will count from the first row in the outermost data region. to start counting in a nested data region, you use the name of the data region. to start counting in a group, you use the name of the group.

      =RowNumber(Nothing)

SSRS and SSAS are supported by VB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.