DAX create empty table with specific column names and no rows

前端 未结 3 1890
南方客
南方客 2020-12-21 21:07

How to create a table with a specified column name and no rows at all. The following oneliner does what I want but shows error message that there should be second argument i

相关标签:
3条回答
  • 2020-12-21 21:28

    This is how I create empty DAX tables:

    EmptyTable = DATATABLE ( "Other Measures", INTEGER, { { 0 } } )

    0 讨论(0)
  • 2020-12-21 21:37

    You could just filter it. Or select TOPN 0.

    TOPN:

    Table = TOPN(0;DATATABLE("Product";STRING;{{}}))
    

    FILTER:

    Table = FILTER(DATATABLE("Product";STRING;{{}});0)
    
    0 讨论(0)
  • 2020-12-21 21:39

    I would like to add to mxix answer a few useful oneliners for making one-column empty table with desired name:

    OneLiner1 = TOPN(0, ROW("Product", "Apple"))
    OneLiner2 = FILTER(ROW("Product", "Apple"), 1=2)
    

    Or if you want to define column type:

    OneLiner3 = TOPN(0, DATATABLE("Product", STRING,{{"Apple"}}) )
    

    So the snipped for bridge table is:

    Product_bridge = DISTINCT(
        UNION(
             TOPN(0, ROW("Product", "Apple"))
            ,DISTINCT(      Sales[Prod_Name]        ) 
            ,DISTINCT( Dictionary[Prod_DifferntName])
            ,DISTINCT(  PriceList[P]                )
            ))
    
    0 讨论(0)
提交回复
热议问题