I have a table visualisation that shows some data. I would like to filter the data so that only data entered the previous working day is shown.
So if the data is refreshed on a Tuesday, then only Monday's data is shown, if on Thursday then only Wednesday data and finally if its refreshed on a Monday, then only Friday's data is shown.
At the moment i can only apply a filter on Power BI desktop for the previous day, which is including weekends (data in the last 1 day)
The data is a simple two column visualisation. In the example below, 17th January is a Friday, so that is the only comment i would like to see on Monday (20th Jan). On the 22nd of January, the only comment i would like to see is the one entered on 21st January:
+-------------+---------------------+
| Date | Comment |
+-------------+---------------------+
| 17-Jan-2020 | Defrosting required |
+-------------+---------------------+
| 20-Jan-2020 | Pallet area cleaned |
+-------------+---------------------+
| 21-Jan-2020 | Workshop not locked |
+-------------+---------------------+
What formula can i use for this please?
Here is what I did.
Data I have is as below
Then I added a new column IsWeekday which will give me True false for weekday with expression
IsWeekday = If( (WEEKDAY(POC[Date Entered]) <> 1 && WEEKDAY(POC[Date Entered]) <>7); "True";"False")
Now my Entire table looks like below
Now we add filters to Table as below
IsWeekday with only True
Then we add Filter for Field Date Entered as Relative date filtering as
is in last days 3 (why 3: because if we are on monday, we want last (sun,sat,friday)
does not include today.
Now add one more filter Date Entered
(Note: you are adding Date Entered twice)
one for last 3 days and one for Top N (1) and by value with Latest date Entered
Why one more date Entered: Because if we are on 31-Jan-2020 i.e Thursday,
Our first filter will give us
Mon,tue,wed,thur,fri
Now our second filter will give us
28-jan,29-jan,30-jan
But we want only 30-jan For (considering 31-jan is today's date)
so last filter will come in play and you will have your desired result.
Let me know if this helps.
Related
I am having a power Bi Report which has a slicer the date column is coming from SQL.
I have Current months Dates till 28-june-2022 and Last years dates in Sql till 30 June 2021
I want only Values to be displayed for todays date in the 2021 Slicer and not all the dates till 30
Screenshot of the Slicer is below
I don't want the Yellow Dates I want the dates to get added automatically when i refresh the other day.
I can do this manually with a filter which is not feasible
If I understand your question correctly, you only want a list of dates within the date range of today and last-year's today. That is the same as the last 12 months of dates. You can do this in the filter pane:
Be sure to un-check the 'Include Today' option.
Another option to select a list of dates between any set of dates is with a measure. Use the following measure to define whatever range of dates you would like. I have done the last full year of dates as an example:
DAX_Dates =
CALCULATE(COUNT('Date'[Date]) --Counts number of records
,KEEPFILTERS( --Allows the filter context of the visuals to dynamically evaluate the calculation
DATESBETWEEN('Date'[Date] --Defines a range of dates to apply the calculation
,DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY())) --Start Date
,TODAY() --End Date
)
)
)
Next, you can filter the visual with the measure.
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]))
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'm trying to overlay three different columns in one chart on Power BI Desktop.
To try to show a comparison of the number of orders per month by different years I have one column for Order Number, and three other columns for Sale Date; Sale Date 2016, Sale Date 2017 and Sale Date 2018. For each order number the three Sale Date columns have a number from 1-12 (representing the month in that year that the order occurred) or a null value (if the order occurred in another year). Something like this:
I'm trying to overlay the three Sale Date columns as individual lines on a line chart with Order Number (Count Distinct) as one axis and Sale Date 1-12 as the other axis. I would think that this would be comparatively simple but Power BI Desktop doesn't seem to have an option to set this up. I'd be open to other types of chart too, as long as the different years can be easily compared.
The reason you're having trouble is that your data is not shaped in a way that is conducive to the way Power BI works.
I'd recommend unpivoting your Sale 201x columns in the Query Editor before trying to do anything. When you do this, your data will look like this instead.
Order # | Year | Month
--------|-----------|------
101 | Sale 2016 | 6
102 | Sale 2017 | 8
103 | Sale 2018 | 12
104 | |
When it's in this format you can use it in a visual much more easily using Order # on your axis and Month for values while using Year as your legend.