Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on Scripting #16

Open
MarkTimson-BIDev opened this issue Jun 30, 2021 · 0 comments
Open

Question on Scripting #16

MarkTimson-BIDev opened this issue Jun 30, 2021 · 0 comments

Comments

@MarkTimson-BIDev
Copy link

MarkTimson-BIDev commented Jun 30, 2021

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 + ")"); 
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant