DAX JOIN if a value is between two dates

℡╲_俬逩灬. 提交于 2019-12-11 08:48:22

问题


In Table A I have a date field called Sales Date. In Table B I have start date, end date, and fiscal quarter. I would like a new Table with the Sales Date from Table A and the fiscal quarter from Table B. How would I do that in DAX? Since most of the UI in PowerBI only allows equality.


回答1:


If you want it as a new table you can do something like this:

NewTable = SUMMARIZECOLUMNS(
               TableA[SalesDate],
               "FiscalQuarter",
               CALCULATE(
                   MAX(TableB[FiscalQuarter]),
                   TableB[StartDate] <= VALUES(TableA[SalesDate]),
                   TableB[EndDate] >= VALUES(TableA[SalesDate])))

You could also just add FiscalQuarter as a calculated column on TableA:

FiscalQuarter = CALCULATE(
                    MAX(TableB[FiscalQuarter]),
                    FILTER(TableB,
                        TableB[StartDate] <= TableA[SalesDate] &&
                        TableB[EndDate] >= TableA[SalesDate]))


来源:https://stackoverflow.com/questions/49539765/dax-join-if-a-value-is-between-two-dates

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