I have set up a table showing number of sick days based on absence start and finish date in Power BI. The date tables have been set up.
I am having an issue with sick days that continue in the following month, for e.g .
Absence Start Date
5 May 21
Absence End Date
5 June 21
My table sums all the absence days in May.
How do I allocate the 25 days in May and then the remaining go to June even though it is one occurrence?
How Data is being summarised
Unfortunately you don't provide enough information about your model/ data. Consider this example. Here is my dummy table:
Table 3 =
var __baseTable =
DATATABLE("StartD",DATETIME, "EndD", DATETIME,
{
{"2020-01-28","2020-02-24"},
{"2019-12-23","2020-01-31"},
{"2020-01-20","2020-02-17"}
}
)
return
ADDCOLUMNS(GENERATE(__baseTable, CALENDAR([StartD],[EndD])),"Month", FORMAT([Date],"yyyy-mm"), "WorkDay", IF(NOt(WEEKDAY([Date]) in {1,7}) ,1,0))
And here are measures (calculating days without a weekend, because I don't have Calendar with businessHoliday):
SumOfSickDays = CALCULATE(SUM('Table 3'[WorkDay]))
Related
Today I come to you with a question regarding a report I am working on finishing up, So I have a lot of Year over year measures in this project, and they all run okay except for 2 of them, its one called "First time complete % 2020" and "Days to first visit 2020", So what is the issue?
When I have a table with claim numbers / customer numbers etc it looks good, I then add the 2021 measures for Current year, this looks good too, when adding the 2020 or prior year measure it is all blank though, and if i do just claim number and remove the Current year measure so i have a table with just prior year and claim number it makes the entire table blank, even the claim number column.
I have attached photos of what I am explaining, the relationship is a 1 to many with 1 being on my calendar side, many on the fact table side.
here is the code for the prior year measure I am using First time complete % 2020 = CALCULATE([Percentage of First Time Complete], 'Calendar(Based on PaidDT Adjusted)'[Year] = 2020)
I have also tried the date add method with CALCULATE([First time complete % 2020], DATEADD('Calendar(Based on PaidDT Adjusted)'[Date], -1, YEAR))
Hope this helps. Thanks
Think about your filter context (filters/slicers/ row level), is there any of them?
If soo, then you need to break this filter by using this kind of calculation:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = 2020))
or something more dynamic:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = SELECTEDVALUE('DateTable'[YEAR])-1 ))
I'm having some difficulty getting a YoY change % for values in Power BI. The averages don't come out proper. I've come to understand this is an AVERAGE vs AVERAGEX issue in Power BI.
I need to create charts of year on year growth monthly. So Jan20 % change from Jan 19. I thought what was below was correct, but it is always throwing an issue for the month of February and a few other months. But some of the months are correct. My Measure is below.
Growth =
IF(
ISFILTERED('Oct5_5'[TRAFFIC_DTE]),
ERROR("Check Time Filter."),
VAR PrevMonth =
CALCULATE(
AVERAGE('Oct5_5'[VISITS_AMT]),
DATEADD('Oct5_5'[TRAFFIC_DTE].[Date], -12, MONTH)
)
RETURN
DIVIDE(
AVERAGE('Oct5_5'[VISITS_AMT]) - PrevMonth,
PrevMonth
)
)
Snippet
Can someone please show me how to use the right Average? Thank you so much!
Do You have all calendar days in your traffice_dte?
Probably not. This causes you to go back to a date that does not exist, which causes an error.
DATEADD function work ok if you use it on "calendar" tabel.
Requirement below:
https://dax.guide/dateadd/
The Date table must always start on January 1 and end on December 31, including all the days in this range. If the report only references fiscal years, then the date table must include all the dates from the first to the last day of a fiscal year. For example, if the fiscal year 2008 starts on July 1, 2007, then the Date table must include all the days from July 1, 2007 to June 30, 2008.
There needs to be a column with a DateTime or Date data type containing unique values. This column is usually called Date. Even though the Date column is often used to define relationships with other tables, this is not required. Still, the Date column must contain unique values and should be referenced by the Mark as Date Table feature. In case the column also contains a time part, no time should be used – for example, the time should always be 12:00 am.
The Date table must be marked as a date table in the model, in case the relationship between the Date table and any other table is not based on the Date.
I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.
I am creating a report with buttons that use a slicer to show the last 3 calendar months, the default view, and YTD. The first two are all set and will continue to work fine, however i am having trouble with the YTD filter because i need it to exclude the current month (some of the key metrics for this slicer are only accurate monthly, even thought the data is updated Daily). Any idea how to accomplish this without me having to manually change it every month? An example of it working today would show me 2020 through August, since September is not complete. September would be included in the filter starting October first. I am thankful for your help/insights!
I typically build a calculated column on my date table called something like "Date in Range", that looks something like the below. You could also apply this to a date in a normal table if you are not using a date dimension.
Date in Range = IF ('MyTable'[Date] <
DATEADD(TODAY(), -1 * DAY(TODAY()), day),
1,
0)
This compares the date in the table row with TODAY(), e.g. 14 Sep 2020, minus the day of the month of today (14), effectively getting you back to the start of the current month. This will then return 1 for dates before the end of last month or 0. Filter on 1 or 0 to get your result (or use something more meaningful in place of the 1 or 0).
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
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])