Skip to content

Question on Scripting #16

@MarkTimson-BIDev

Description

@MarkTimson-BIDev

Hi Tabular Editor guys,

I couldnt find a place to ask general questions on scripting, working with Daniels example I was trying to create some measures changing the measures format string but first checking the source col to change the format accordingly if Value then "£ #,##0" if Unit then "#,##0" Is there any way to achieve this in the advance scripting, the documentation could be slightly better. As most of the people that would use this are BI developers and not C# programmers.

Your help would be appreciated on this and examples added would be beneficial to get some traction on users using the advance scripting or Macros in T3.

Example code below:

foreach(var c in Selected.Columns)
{
    //Set Default Summerizations of all cols to null
    c.SummarizeBy = AggregateFunction.None ;

    // Hide the base column:
    c.IsHidden = true;

    var newMeasure = c.Table.AddMeasure(
    "Sum of " + c.Name,                    // Name
    "SUM(" + c.DaxObjectFullName + ")"    // DAX expression
    );
    
    //Set the format string on the new measure:

    if (c.Datatype == Datatype.Double)
    {
        newMeasure.FormatString = "£ #,##0";
        Output("Measure will be created for columns with the data type: " + c.DataType.ToString() + " (" + c.DaxObjectFullName + ")");
        
    }
    else
    {
        if(c.Datatype == Datatype.Int64)
        newMeasure.FormatString = "#,##0";
        Output("Measure will be created for columns with the data type: " + c.DataType.ToString() + " (" + c.DaxObjectFullName + ")"); 
    };
    
    // Display Folder
    newMeasure.DisplayFolder = "Basic Measures" ;    

    // Provide some documentation:
    newMeasure.Description = "SUM(" + c.DaxObjectFullName + ")";
    
}

The code Errors on the If Statement.

    if (c.Datatype == Datatype.Double)
    {
        newMeasure.FormatString = "£ #,##0";
        Output("Measure will be created for columns with the data type: " + c.DataType.ToString() + " (" + c.DaxObjectFullName + ")");
        
    }
    else
    {
        if(c.Datatype == Datatype.Int64)
        newMeasure.FormatString = "#,##0";
        Output("Measure will be created for columns with the data type: " + c.DataType.ToString() + " (" + c.DaxObjectFullName + ")"); 
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions