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

Put Measures at end of DAX Scripts when scripting calculated tables (Field Parameters, Calculation Groups, etc.) #1432

Open
edhans opened this issue Jan 23, 2025 · 1 comment
Labels
issue: under review Being looked into by TE team

Comments

@edhans
Copy link

edhans commented Jan 23, 2025

Description

If you create measures in a calculated table, then script the table, the measure is put at the top of the script.

If you later run the script where the table doesn't exist, you get an error because TE/3 has no where to put the measures because the referenced table doesn't exist.

If you move Measures to the bottom of the DAX script, it works fine though. The below script in a Contoso database will fail because the "Test CG" calc group doesn't exist at the time the measure script lines are run, but this is the code and order that TE/3 created when I scripted the CG with the measure in it.

---------------------------
-- Measure: [Measure in CG]
---------------------------
MEASURE 'Test CG'[Measure in CG] = SELECTEDVALUE('Product'[Product Name]) IN VALUES('Product'[Brand])

-------------------------------
-- Calculation Group: 'Test CG'
-------------------------------
CALCULATIONGROUP 'Test CG'[Name]

    CALCULATIONITEM "The Doubler" = SELECTEDMEASURE() * 2

Tabular Editor 3 Version

3.19

Screenshots

No response

Steps to Reproduce

No response

Expected behavior

No response

Crash Report

No response

Windows Version

No response

@edhans edhans added the template: issue Issue report created by user, needs to be triaged label Jan 23, 2025
@edhans edhans changed the title Put Measures at end of DAX Scripts when scripting calculated tables (Field Parameters, Calculation Groups, etc. Put Measures at end of DAX Scripts when scripting calculated tables (Field Parameters, Calculation Groups, etc.) Jan 23, 2025
@mlonsk
Copy link
Collaborator

mlonsk commented Jan 23, 2025

Hi @edhans
Yes, I can see and repo the issue, but I believe it is only DAX Scripts of CGs that are affected as you show in your example.

If I script a regular calculated table, the measures are put at the bottom, and the script works as expected.

An example from the SpaceParts dataset:

---------------------------------------
-- Calculated Table: 'On-Time Delivery'
---------------------------------------
TABLE 'On-Time Delivery' = 
    ADDCOLUMNS (
        FILTER (
            DISTINCT ('Invoices'[OTD Indicator]),
            NOT ISBLANK ('Invoices'[OTD Indicator])
        ),
        "OTD Status",
            SWITCH (
                TRUE (),
                'Invoices'[OTD Indicator] = TRUE, "On Time",
                "Late"
            ),
        "OTD Sort Order",
            SWITCH (
                TRUE (),
                'Invoices'[OTD Indicator] = TRUE, 1,
                2
            )
    )

---------------------------
-- Measure: [OTD % (Lines)]
---------------------------
MEASURE 'On-Time Delivery'[OTD % (Lines)] = 
    VAR _OnTime = [OTD (Lines)]
    VAR _Total = CALCULATE (
        [Invoice Lines],
        'Invoice Document Type'[Group] = "Invoice"
    )
    RETURN
    
    DIVIDE ( _OnTime, _Total )
    , DisplayFolder = "3. Lines"
    , FormatString = "#,##0.0%"

@mlonsk mlonsk added issue: under review Being looked into by TE team and removed template: issue Issue report created by user, needs to be triaged labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: under review Being looked into by TE team
Development

No branches or pull requests

2 participants