Power Bi DAX: Divide Value and set it for each week

天涯浪子 提交于 2020-03-25 13:42:35

问题


I have a target value of 20 for January but it is 20 for the month, i need to show this over each week. I have to divide the target by 4 if there are 4 weeks in a month and by 5 if there are 5 weeks in a month. It is as simple as that, i am using a line and clustered column chart to display my data, i need the target spread out into each week of the month. I also need another field to do this but im sure i can replicate your formula and make it applicable.

I have added a WeeksinMonth column that counts how many weeks are in a particular month e.g January has 5 weeks and February has 4 weeks. I need an IF statement that will divide the target and value by how many weeks in a month. e.g if month has 5 weeks then divide target and value by 5, if month has 4 weeks divide target and value by 4.

I have a calendar table with week values which i can used to put the divided target into and also the desired output i made in excel (See attached).

How will i go about this?

Desired Output

Calendar Table


回答1:


enter code hereYou can create an extra column in your calendar table:

WeekMax = 
var stOfMonth = Weeks[Start of Week].[Month]
var stOfYear = Weeks[Start of Week].[year]
return CALCULATE(max(Weeks[Weekinmonth]);FILTER(Weeks;Weeks[Start of Week].[Month] = stOfMonth && Weeks[Start of Week].[Year] = stOfYear))

Make sure you have a relation in your model between calendar and target date. Now you can use this number for that week/date to divide by.

You can now add an extra column in your target table:

WeeklyTarget = Targets[Target]/Related(Calendar[WeekMax])


来源:https://stackoverflow.com/questions/60227985/power-bi-dax-divide-value-and-set-it-for-each-week

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