Relative Date filtering Query Editor - Power BI - date

I don't understand the logic of Power Query Editor.
I have a big table with data from 2019 to 2024 (one column contains the monthly information).
I want to filter the data by the date of that column, but it has to be dynamic.
Two options:
The data I want to consider is "Current month -2". So all historical data minus current month.
The data I want to consider is a parameter extracted from somewhere (e.g. I set the latest month to consider manually somewhere in an Excel, which usually is "current month -1" but not always (best).
I would be happy with any of the two solutions.
Currently I found somewhere this formula which filters out vs last month:
= Table.SelectRows(#"Changed Type",each [Month]< Date.From(Date.StartOfMonth(DateTime.LocalNow())))
But somehow I do not find the way to go 2 months back.
Thanks a lot!
BR

Related

How can I calculate my win rate on one column based on the date on another?

I created a rudimentary Google Form to track my win rate at Starcraft. The first column on the resulting Google Sheet is Timestamp created by the form.
I have another column that has my win-loss, and I am able to calculate my percentage for the entire sheet (all games). However, I want to be able to see my daily win rate, and I can't figure out the correct way to go about it.
I tried COUNTIF, COUNTIFS, with TODAY() and I was able to count the games for a certain day, but I don't know how to use it to tie in with my win-loss column. What I currently do is adjust my Daily formula to specify today's date before playing. I was hoping I won't need to do this.
Please see Win-Loss Stats Sheet
Solution:
You can extend your formula to compare against the date in column A:
=(COUNTIFS(D2:D, "Win", ARRAYFORMULA(INT(A2:A)),TODAY())/((COUNTIFS(D2:D, "Win",ARRAYFORMULA(INT(A2:A)),TODAY()))+(COUNTIFS(D2:D, "Loss",ARRAYFORMULA(INT(A2:A)),TODAY()))))
The additional condition would be ARRAYFORMULA(INT(A2:A)),TODAY(), which converts the timestamps into dates and compares them to today's date.
Sample Output:

Power BI Week Visual Filtering

Power BI novice here. I have multiple reports which require date filtering by week. I can sometimes get the data to display with my Week column using dates from a column in the same table.
I thought building a Week column based on the date column would result in an easy to use visual. The week column is calculated by:
WeekYear = IF(
FORMAT(WEEKNUM(START.[Date],1)-1,"00"="00",
"Wk53-" & YEAR(START.[Date])-1,
"Wk" & FORMAT(WEEKNUM(START.[Date],1)-1,"00") & "-" & YEAR(START.[Date]))
This results in an x-axis displaying weeks in this format: Wk52-2019. If the underlying data of column STARTis in the proper datetime format, what could be the issue?
I noticed data on the visual which is not filtered for a date range display without issue. Trying to filter with DATESINPERIOD or other DAX date filters caused calculated measures to not display or break the model. I know a lot of references state having a separate calendar table is critical and I suppose I don't fully understand. Thanks in advance.
If you are trying to create the week in date format, then you can use the following calculation:
Week = Table[Start] - WEEKDAY(Table[Start],2)+1
This returns the Monday date of the week, if you want other days you can adjust the calculation accordingly.
If this is not what you are looking for, then you might have to clarify your requirements a bit more.

How can I set a non-continuous date filter?

I need to be able to filter my data to comparable weeks/months across various years. And I need to be able to update those choices on the fly. Is there a way in tableau to set a non-continuous date filter?
because the base data is saved on the tableau server, I'm unable to join additional tables to it, so my initial idea of making a table of year / start date / end date and joining that to my data with a simple t/f filter isn't panning out.
I've considered making series of parameters, but it seems like it might get a bit overwhelming to make so many
Other things I've considered is writing an extended rule like
IF [year] = 2015 THEN [date]BETWEEN(date A, date B)
or the tableau equivalent to BETWEEN
ELSEIF [year] = 2016 THEN [date]BETWEEN(date C, Date D)
ELSE IF //and so forth
Does anyone else have experience with this? Any strategies you might recommend on the parameters vs. a long formula?
Any ideas are greatly appreciated!
Standard tableau filters on dates allow filtering by both continuous date ranges or filtering by parts of dates.
For example, if you wanted to compare January sales cross multiple years, you can drag your date field to the filters shelf and then right-click the date field in the shelf and choose "Discrete" rather than "Continuous" or choose "Month" in the upper set of options about which date component you want (the upper set selects date components, the lower set selects date ranges with in filters and axes).
So, if you put a date field on the filters shelf and select "month" as a discrete you will get a filter that allows you to filter for every January in the dataset.

PowerBI: How to display/filter row tables between 2 years dynamically

I was wondering if there's a way where I can filter out my table results based on two years. My table A has date column and many miscellaneous columns. So currently I would like the table A to display January 2018 (or 1/1/2018) and December 2019 (or 12/31/2019 --basically ongoing) information. However, once January 1st, 2020 appears, I would like my table A to display row results between January 2019 and December 2020. Is there a way I can do so? Maybe in DAX or clicking some filter option? Could someone show me? I'm still fairly new to PowerBI.
Thanks
The easiest way to meet this requirement is usually using the Relative Date Slicer or Filter functionality:
https://learn.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range
Not sure if any of those options will meet your scenario. Maybe Last 12 Months (Calendar)? Your requirements description didnt make much sense to me - you probably need to explain "ongoing" and "appears".
If the Relative Date functions dont meet your needs, then you'll need to construct a column (in Power Query or DAX) that returns a static value you can use in a Slicer or Filter.

Loading date or datetime into date dimension

Let's say I have a date dimension and from my business requirements I know that the most granular I would need to go is to examine the specific day of the month that an event occurred.
The data I am given provides me with the exact time that an event occurred (YYYY-MM-DD HH:MM:SS). I have two opitons:
Before loading the data into the date dimension, slice the HH:MM:SS from the date.
Create the time attributes in my date dimension and insert the full date time.
The way I see it, I should go with the option 1. This would remove redundant data and save some space. However, if I go with option 2, should the business requirements ever change or if my manager suddenly wants to be more granular I wouldn't need to modify my original design. Which option is more commonly used? Are there more options that I did not consider?
Update - follow up question
I receive new data every month. If I used a pre built date dimension with all the dates would I then need to run my script every month to populate the table with new dates of that month or would I have a continuous process where by every day insert into the table one row, which would be that date?
I would agree with you and avoid option 2. A standard date dimension table is at the individual date level. If you did need to analyse by time of day, you could create an additional time of day dimension at the level of a second in a single day, and link to that from your fact table.
Your date dimension should be created by script automatically, rather than from the dates that events occurred. This allows you to analyse across a range of events from other facts, and on dates where no events occur, using a standard, prebuilt dimension.
I would also include the full date/time stamp as a column in the fact table, along with the 'DateKey' to the dimension table. This would allow you some visibility/analysis of the timestamp, you would not lose the data, and would still allow you to analyse by the date dimension.
Update - follow up question
Your pre-built date dimension (the standard way of doing it) would usually contain some dates in the future. There's no reason not to, for example, include another 5 years of dates in the table. But if you'd like it to gradually grow over time, you could have a script that is run once a day, once a month, or once a year to add new dates. Its totally up to you! There are many example scripts for building date dimensions- just google date dimension script. They exist for the language of your choice, e.g. SQL, C#, Power Query, etc.