简体   繁体   English

Dax 日历,不同国家的不同部门都有假期,power bi

[英]Dax calender with holidays for different divisions in different countries, power bi

I have a pretty big calender table made in Dax, with about 40 different columns.我有一个用 Dax 制作的非常大的日历表,大约有 40 个不同的列。 I introduced an additional holiday table to make two columns in the calender table: "Holiday" and "IsWorkday".我引入了一个额外的假期表来在日历表中创建两列:“假期”和“IsWorkday”。 This works fine, but now i have divisions in a different country, and therefor these two columns must be dynamic based on the division.这很好用,但现在我在不同的国家有分部,因此这两列必须基于分部是动态的。

The tables that are relevant are sales, division, calender and holiday.相关的表是销售额、部门、日历和假期。 Calender and division is both related to sales.日历和分区都与销售有关。 The holiday table is only used with LOOKUPVALUE in the calender table.假日表仅与日历表中的 LOOKUPVALUE 一起使用。

Simplified preview: [Simplified preview][1] [1]: https://i.stack.imgur.com/FQv5G.png简化预览:[简化预览][1] [1]:https://i.stack.imgur.com/FQv5G.png

The two columns in the Dax calender looks like this, (where [Date] not from Holiday is the Date from the Calender dax) Dax 日历中的两列看起来像这样,(其中 [Date] 不是来自 Holiday 是来自 Calender dax 的日期)

    "Holiday",                          VAR DivisionCountry = LOOKUPVALUE(Division[Country], Division[DivisionID], SELECTEDVALUE(SALES[DivisionID]))
                                        VAR Country = LOOKUPVALUE(Holiday[Country], Holiday[Country], DivisionCountry)
                                        RETURN
                                        LOOKUPVALUE(Holiday[Holiday],Holiday[Date],[Date], Holiday[Country], Country),
                                        
    "IsWorkday",                        VAR WeekdayNum = WEEKDAY( [Date], 2)
                                        VAR DivisionCountry = LOOKUPVALUE(Division[Country], Division[DivisionID], SELECTEDVALUE(SALES[DivisionID]))
                                        VAR Country = LOOKUPVALUE(Holiday[Country], Holiday[Country], DivisionCountry)
                                        VAR Integer = INT( NOT WeekdayNum IN {6, 7} && ISBLANK(LOOKUPVALUE(Holiday[Holiday],Holiday[Dato],[Date],Holiday[Country], Country) ) )
                                        VAR Result = Integer
                                        RETURN Result,

'Holiday' returns blank even when i select different divisions.即使我 select 不同的部门,“假期”也会返回空白。 'IsWorkday' is able to return 1 for mondays-fridays when i comment out the holiday-part, but returns 0 when i include it.当我注释掉假期部分时,'IsWorkday' 能够在星期一至星期五返回 1,但在我包含它时返回 0。 The Holiday-part of the two columns are basically the same.两列的Holiday-part基本相同。

Im not that good at Dax, and i admit that i probably dont understand the real logic of the dax that i've written here, as my logic clearly fails.我不太擅长 Dax,我承认我可能不理解我在这里写的 dax 的真正逻辑,因为我的逻辑显然是失败的。

I really appreciate any help or tips to get me closer to a solution.我非常感谢任何帮助或提示,让我更接近解决方案。 Hopefully the information i have provided is sufficient.希望我提供的信息足够。 If not - please let me know and i will add.如果没有 - 请告诉我,我会添加。

Thank you!谢谢!

I would begin by creating a relationship between Calendar[Date] and Holiday[Date] .我将从在Calendar[Date]Holiday[Date]之间建立关系开始。 Next, I would create a measure HolidayName to return the holiday for a given [Date] and [DivisionID] .接下来,我将创建一个度量HolidayName以返回给定[Date][DivisionID]的假期。

HolidayName = 
    
VAR DivisionCountry = LOOKUPVALUE(Division[Country], Division[DivisionID], SELECTEDVALUE(Sales[DivisionID]))

RETURN

LOOKUPVALUE(Holiday[Holiday], Holiday[Date], SELECTEDVALUE(Calendar[Date]), Holiday[Country], DivisionCountry) 

Then you could make another measure isWorkdayOrHoliday to combine Calendar[isWorkday] and the newly made measure HolidayName .然后,您可以进行另一项措施isWorkdayOrHoliday以组合Calendar[isWorkday]和新制定的措施HolidayName

isWorkdayOrHoliday = INT(Calendar[isWorkday] && ISBLANK([HolidayName]))

This would return isWorkdayOrHoliday = 0 if a given date is either a weekend or holiday.如果给定日期是周末或假日,这将返回isWorkdayOrHoliday = 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM