DAX create empty table with specific column names and no rows

久未见 提交于 2019-12-11 07:47:55

问题


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 in ROW function.

EmptyTable = ROW ("Product")

I would like to use it for making bridge tables with desired column name. For example I want Product_bridge table to have a column "Product".

Product_bridge = DISTINCT(
    UNION(
         DISTINCT(      Sales[Prod_Name]        ) 
        ,DISTINCT( Dictionary[Prod_DifferntName])
        ,DISTINCT(  PriceList[P]                )
        ))

The code above gets me the name of the first table, in this case Prod_Name.


回答1:


You could just filter it. Or select TOPN 0.

TOPN:

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

FILTER:

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



回答2:


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]                )
        ))


来源:https://stackoverflow.com/questions/57689581/dax-create-empty-table-with-specific-column-names-and-no-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!