Issue in formatting date/numeric columns in SSRS matrix report - matrix

Mine is tablix report, with columns and values. Which are dynamically generating.
Issue is, there are some date and numeric columns which i want to format, and for that i am trying below given expressions:
=IIf(Fields!ColumnName.Value = "Charge",
FormatCurrency(Fields!Value.Value, 2),
IIf(Fields!ColumnName.Value = "StartDate",
FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
IIf(Fields!ColumnName.Value = "EndDate",
FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
Fields!Value.Value
)
)
)
OR
=Switch
(
Fields!ColumnName.Value = "Charge", FormatCurrency(Fields!Value.Value, 2),
Fields!ColumnName.Value = "StartDate", FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
Fields!ColumnName.Value = "EndDate", FORMAT(CDate(Fields!Value.Value),"MM-dd-yyyy"),
true, Fields!Value.Value
)
OR
=IIF(IsNumeric(Fields!Value.Value), FormatNumber(Fields!Value.Value, 2), Fields!Value.Value)
none of them are working, it changes the number columns correctly and then it gives #Error in every columns.

Add the following custom code to your report
Public Function FormatColumn(columnName As String, value AS String) As String
Select columnName
Case "Charge"
Return Format(CLng(value), "c2")
Case "StartDate"
Return Format(CDate(value),"MM-dd-yyyy")
Case "EndDate"
Return Format(CDate(value),"MM-dd-yyyy")
Case Else
Return value
End Select
End Function
Set the cell expression to
= Code.FormatColumn(Fields!ColumnName.Value,Fields!value.Value)

Related

Excel PowerQuery: how do I add an IsNotNull column

I have a simple function that I'd like to run on the values in a column, resulting in another column.
let
ThisIsNotNull = (input) => if (input = null) then false else true,
Source = ...
eventually there is a text column with Nulls in it, let's call it TextColumn.
I'd like to add another column alongside it with a value of =ThisIsNotNull(TextColumn).
Add column... Custom column with formula
= ThisIsNotNull([NameOfColumnToTest])
But really you can skip the function and just use
= if [NameOfColumnToTest] = null then false else true

Determine column on which invoke custom function

I am trying to invoke a function on an added column that will concatenate two columns. The catch is that I can't use the column name shorthand as I use dynamic parameters using strings to determine the column name.
Therefore the result is that I get a column as a List multiplied per row rather than the concatenated value for the specific row as intended
(func as text) =>
let
Source = Excel.CurrentWorkbook(){[Name="DataTBL"]}[Content],
\\This is the string extraction process for the parameter
funcTrig = Text.Start(func, 1),
columnA = "" & Text.BetweenDelimiters(func,"_","_") & "",
columnB = "" & Text.AfterDelimiter(func,"_",1) & "",
\\converting the string to column data
Convert2ColA = Table.Column(Source,columnA),
Convert2ColB = Table.Column(Source,columnB),
\\function to concatanate column A value at a specific row with column B value at the same row.
concat= StraightForward(Convert2ColA ,Convert2ColB)
in
concat
I have outlined with remarks the process and desired results, In the added picture I have pulled out the result of "Convert2ColA" what is the desired result will be 1999 in row one and so on.

Setting Linq2Db to read and update with CHAR type and NOT NULL constraint in Oracle

Reading value of fixed CHAR string from table, using Linq2db Oracle provider:
CREATE TABLE mytable
(pk NUMBER(15,0) NOT NULL,
fixed_data CHAR(20) DEFAULT ' ' NOT NULL)
Although in database, length of FIXED_DATA filed is 20,
SELECT LENGTH(fixed_data) FROM mytable WHERE pk = 1
-- result is 20
When same field is read using Linq2Db, value gets truncated to empty string:
var row = (from row in database.mytable where row.pk == 1 select row).ToList()[0];
Console.WriteLine(row.fixed_data.Length);
// result is zero
This causes problem when record is updated using Linq2Db, Oracle converts empty string to NULL, and UPDATE fails:
database.Update(row);
// Oracle.ManagedDataAccess.Client.OracleException: 'ORA-01407: cannot update ("MYSCHEMA"."MYTABLE"."FIXED_DATA") to NULL
Is there any setting in Linq2Db for read->update cycle to work with CHAR type and NOT NULL constraint?
Found a solution, thanks to source code openly available. By default, Linq2Db calls expression IDataReader.GetString(int).TrimEnd(' ') on every CHAR and NCHAR column. However this can be easily customized, by implementing custom provider, which overrides field value retrieval expression, with one that does not trim:
class MyOracleProvider : OracleDataProvider
{
public MyOracleProvider(string name)
: base(name)
{
// original is SetCharField("Char", (r,i) => r.GetString(i).TrimEnd(' '));
SetCharField("Char", (r, i) => r.GetString(i));
// original is SetCharField("NChar", (r,i) => r.GetString(i).TrimEnd(' '));
SetCharField("NChar", (r, i) => r.GetString(i));
}
}

Access field value in a function in Power Query M

I want to create a function that gets the first value of a table field if two other field values match the two given function parameters.
I thought this would be easy. But I found nothing in the internet or M documentation that could solve this.
I don't know if I have to loop through a record or if there is a top level function.
= (val1 as text, val2 as text) as text =>
let
result = if [Field1] = val1 and [Field2] = val2 then [Field3] else ""
in
result
As far as I understand your wish, table and column names are hard coded (i.e. you intend to apply the function only for specific table). Then you may use following approach:
// table
let
t1 = #table({"Field1"}, List.Zip({{"a".."e"}})),
t2 = #table({"Field2"}, List.Zip({{"α".."ε"}})),
join = Table.Join(t1&t1,{}, t2&t2,{}),
add = Table.AddIndexColumn(join, "Field3", 0, 1)
in
add
// func
(val1 as text, val2 as text) => Table.SelectRows(table, each [Field1] = val1 and [Field2] = val2)[Field3]{0}
// result
func("d","β") //31

auto sorting multiple columns, secondary column triggers resort too

I have a sorting question. I have two columns in my table that I need to sort by (primary=column 1, secondary=column 4). I am using the script below and it works for sorting by column 1, and it works for sorting column 4 if I also make a change in Column 1 but not by itself. I would like to be able to edit a value JUST column 4 value and have it do the secondary sort.
Ex: Column 1: Date, Column 2: LastName, Column 3: DOB, Column 4: Payment
I'd like to maintain the spreadsheet in date order (ascending, allowing repeat values), but secondarily organized by payment amount (ascending). That way I can see by date the order of highest to lowest payments. If I change JUST the payment data in a cell, I'd like it to resort by column 1 (date) and then 4 (payment). This script is not accomplishing that last bit. Any advice?
/**
* Automatically sorts the 1st column (not the header row) Ascending.
*/
function onEdit(event){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 1;
var tableRange = "A2:T99"; // What to sort.
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( [1, 4] ); // or
range.sort( [{ column: 1, ascending: true }, 4] ); // or
range.sort( [{ column: 1, ascending: true }, { column: 4, ascending: true }] );
}
}
Probably I don't understand the problem? I suggest to change your if statement from
if(editedCell.getColumn() == columnToSortBy){
...
}
to
if((editedCell.getColumn() == columnToSortBy) || (editedCell.getColumn() == 4)){
...
}

Resources