DAX Query Generator

Coordinator
Mar 14, 2016 at 5:59 PM
Edited Mar 14, 2016 at 6:03 PM
API Ranet UI lets you create a DAX-query layout structure in terms of the areas of the columns and filters. On the basis of this structure generates DAX-query.
AttributeColumn year = new AttributeColumn("Date", "Calendar Year");
year.FilterValues.Add("2006");

AttributeColumn date = new AttributeColumn("Date", "Date", true);
date.FilterValues.Add("DATE(2006,1,1)");
date.FilterValues.Add("DATE(2006,1,2)");

AttributeColumn countryRegion = new AttributeColumn("Geography", "Country Region Name", true);

AttributeColumn product = new AttributeColumn("Product", "Product Category Name", true);
product.FilterValues.Add("\"Bikes\"");
product.FilterValues.Add("\"Clothing\"");

MeasureColumn totalSales = new MeasureColumn("Sales Territory", "Total Sales");

QueryStructure queryStructure = new QueryStructure();
queryStructure.Columns.Add(year);
queryStructure.Columns.Add(date);
queryStructure.Columns.Add(countryRegion);
queryStructure.Columns.Add(product);
queryStructure.Columns.Add(totalSales);

Operator exp1 = new Operator(new Column(year), "=", new DaxFragment("2007"));
Operator exp2 = new Operator(new Column(countryRegion), "=", new DaxFragment("\"United States\""));
Operator exp3 = new Operator(exp1, "&&", exp2);
Parentheses exp4 = new Parentheses(exp3);
Operator exp5 = new Operator(new Column(year), "=", new DaxFragment("2008"));
Operator exp6 = new Operator(new Column(countryRegion), "=", new DaxFragment("\"United Kingdom\""));
Operator exp7 = new Operator(exp5, "&&", exp6);
Parentheses exp8 = new Parentheses(exp7);
Operator exp9 = new Operator(exp4, "||", exp8);
Operator exp10 = new Operator(new Column(new MeasureColumn("Internet Sales", "Internet Total Sales")), ">", new DaxFragment("200000"));
Operator exp11 = new Operator(exp9, "||", exp10);
queryStructure.Filters = exp11;

string daxQuery = DaxGenerator.Generate(queryStructure);
According to this source code will be generated following DAX query:
EVALUATE
SUMMARIZE(
    SUMMARIZE(
        FILTER(
            CROSSJOIN(
                FILTER(
                    FILTER(
                        SUMMARIZE(
                            'Date',
                            'Date'[Calendar Year],
                            'Date'[Date]
                        ),
                        ('Date'[Calendar Year] = 2006)
                        &&
                        ('Date'[Date] = DATE(2006,1,1) || 'Date'[Date] = DATE(2006,1,2))
                    ),
                    (NOT ISBLANK('Sales Territory'[Total Sales]))
                ),
                FILTER(
                    VALUES(
                        'Geography'[Country Region Name]
                    ),
                    (NOT ISBLANK('Sales Territory'[Total Sales]))
                ),
                FILTER(
                    FILTER(
                        VALUES(
                            'Product'[Product Category Name]
                        ),
                        ('Product'[Product Category Name] = "Bikes" || 'Product'[Product Category Name] = "Clothing")
                    ),
                    (NOT ISBLANK('Sales Territory'[Total Sales]))
                )
            ),
            (NOT ISBLANK('Sales Territory'[Total Sales]))
            &&
            (
                (
                    'Date'[Calendar Year]
                    =
                    2007
                    &&
                    'Geography'[Country Region Name]
                    =
                    "United States"
                )
                ||
                (
                    'Date'[Calendar Year]
                    =
                    2008
                    &&
                    'Geography'[Country Region Name]
                    =
                    "United Kingdom"
                )
                ||
                'Internet Sales'[Internet Total Sales]
                >
                200000
            )
        ),
        ROLLUP(
            'Date'[Date],
            'Geography'[Country Region Name],
            'Product'[Product Category Name]
        ),
        'Date'[Calendar Year],
        "Total Sales",
        'Sales Territory'[Total Sales]
    ),
    'Date'[Calendar Year],
    'Date'[Date],
    'Geography'[Country Region Name],
    'Product'[Product Category Name],
    [Total Sales]
)
ORDER BY
    'Date'[Calendar Year],
    'Date'[Date],
    'Geography'[Country Region Name],
    'Product'[Product Category Name]
A full-featured visual designer DAX-query will be implemented in the short version Ranet UI.