Creating Date Relationship in Power BI for Slicers - powerbi

I'd like to slice across visuals based on dates in MS Power BI (i.e., one filter for say month will slice all visuals for that time period.
I created a date table from http://www.agilebi.com.au/power-bi-date-dimension/ to link to the date columns in each table.
I connected xlsx workbook.
Image of columns in Power BI
I added tried to edit the relationship so connect the 2 date columns. However, when I insert the filter using the date_table as values and try to use it, the visuals disappear.
Visuals are Gone
However, when I create the slicer and slice across multiple visuals, they go blank.
**I tried changing the type to "Both" but it didn't fix the problem.

The script at AgileBI.com.au creates a date table with a 'Date' field that has a data type of text. You can (surprisingly) do a relationship between 2 fields of different data types and not get an error. However, a join between a text field that contains dates, and a regular date field will mean that rows that look like they should match up do not.
You can confirm this is happening by picking a value in the 2 tables that you think should match up and seeing if they are identical. In my case, I had Tuesday, November 01, 2016 in my imported table, and 11/1/2016 in the other table. While they both represent the same date (in the US), they clearly look different. A good place to see this is in the Edit Relationship screen (and it definitely would have been helpful to include a screenshot of that in your original post).
Anyway, if the dates in your table don't match up to the corresponding (text) dates in the Date table, then when you filter to "2016" on your slicer, the visuals will all go blank.
I would recommend:
Click Edit Queries
On the left hand side, select the table of dates (called Invoked Function by the script)
Click on the header for the Date column (it will likely already be selected)
Select Transform on the ribbon
Change the Data Type from Any to Date
Click Home > Close & Apply
Hope this helps.

Related

How do I create a slicer that only affects one column in Power BI?

I have a table with multiple columns, I would like to add a "Previous Date Slicer" so that there is a column that will fetch data from previous dates that the user selects, but it applies this slicer to the entire table so I can't actually create a comparative column and the entire table is filled with data from the dates I have selected.
The intent is that the Previous Data Column will display the information from the previous dates I selected in the slicer column, creating a comparison. One column will have the current dates data, and the other column will have the previous dates data from dates the user specified.
you should be able to do this by "Edit Interactions" feature.
When you have the slicer highlighted you will see a "Format" pane in the top many and the first button on this page is the one you want. One you enabled "Edit Interactions" some extra icons will apear on the other objects and all object is by default set to filter. You can change the object you don't want to be filtered by the slicer to "None"

Line Graph in Power BI

Two-line graph with slicers: Everything looks fine until date selections are made.
I figure that this failure has something to do with the line graph and date functionality. Date selections work together in a very weird way. Selecting only 2019 months and then only 2020 months, both lines disappear.
If the date slicers are going to work together, I should expect inclusive behavior, rather than "NOT 2020 AND NOT 2019"!
See relationships.
How do I get the behavior intended on one two-line graph?
Thanks!
I agree with #teylyn, sometimes less is more.
The problem is how Power Bi works and how your measures are calculated. You have two averagex-measures, both pointing to same date table. In Power BI, two separate filters from a single dimension can't do "union", they are laid down on top of each other. You are telling that first I want to filter by 2019 November and after the filter has been evaluated, you tell that you want to filter 2020 January. Power BI adds new filter to already filtered dataset, but the dataset doesn't contain anything that match both filters, so the end result is empty.
One way to get around this problem is to create separate date-tables for filtering purposes for blue and green. Here is an example of the data model needed:
Then you update the date-filters in second tab. Set blue date filter to one date-dimension and green date filter to another. This way they aren't filtering the same table and the graph should work the same as before.

How to use a single date table for two date fields?

I'm using Power BI Desktop to explore some data. I have a table called "Reports" which contains a list of reports that need to be filed. There are two date fields, "Due Date" and "Date Completed".
I have a single date table, Dates. It has been marked as my date table in Power Bi.
My goal is produce a matrix where each row is a month in the due date and each column is a month in the date completed. However, I can't figure out how to get Power BI to use the dates table for both of my date fields. I can join it in the relationships pane - but it looks like I can have only a single active relationship at a time. I've also tried the "Get Data" feature to add the date table multiple times, but it will only add once.
How can I use my date table for more than one date field at a given time?
You need to create two relationships to the dates table-- one is Active, one is Inactive. All measures will use the Active relationship, and to calculate data in the reports using the inactive relationship you create DAX Measures using the USERELATIONSHIP() function.
Here is a couple resources:
https://www.sqlbi.com/articles/userelationship-in-calculated-columns/
https://carldesouza.com/power-bi-dax-userelationship-multiple-dates/

Power BI Desktop - Relative Date Slicer Defaulting to Days

Hoping this is a simple one to resolve.
I have a dataset, a SQL View, with the data imported into my PBIX. I have a date slicer and a number of tables, matrices and charts, over 2 pages. All update whenever I change my slicer, great.
One of my charts needs to show the last 12 months only. I choose Relative Date Filtering from the Visual level filters, select "is in the last", 12 and months from the various drop-downs. When I click Apply filter, my chart goes blank, even though there is data. When I click off the chart and back on again, the drop-down has changed to Days, not months. I have tried with various different options and always defaults back to days.
My Date field is definitely a Date. I have also tried adding a Date table and using that date too but the same thing happens.
Is it me or is there a bug?
Thanks

Change column values based on slicer selection

Using PowerBI desktop, I have created a small table (called TimeSelector), with three elements: Day, Week and Month
The idea is to use the content of this table to create a slicer with three options
Thus, selecting one of those options should change the way dates are used in tables.
For instance, selecting Day would result in the following table:
While selecting Week would result in this:
Etc..
I have tried to write a new measure taking in account the selected slicer element, but it is not working:
DayWeekMonthSelection = IF(CONTAINS(TimeSelector;TimeSelector[DayWeekMonth];"Month");
MONTH(VALUES('uptime_downtime'[Uptime_date])))
This is only the first part of the formula, only testing the month option as a start.
Any idea on how to do this?
To offer another perspective:
The approach I take with this is to have a separate table in the database - containing meta data about the date, called date_lookup.
2 of the fields in this table are FirstDateOfMonth & FirstDateOfWeek.
Some of the other fields are lastDateOfMonth & LastDateOfWeek, also DayOfWeek.
By using these fields I can easily present visuals that are grouped by month or week.
Sure you can use functions to get this information, but functions can be platform dependant. If you're making a join to the date_lookup anyway - it's no more effort to get this info from there...
The main reason we need to store this meta data is our company Financial year is Jul - Jun. Therefore we need to have available the Correct FY - which is stored as a field in the date_lookup table. I also have fields in there identifying public holidays...
This is an interesting question, but I'm not sure how to do exactly what you are asking for, so I'll suggest an alternative. (Changing a measure based on a slicer selection isn't too difficult, but I'm not sure a good way to swap out a field/dimension.)
Instead of creating a separate table for your slicers, a different possible approach would be to create a date hierarchy. Often when you drag a date column into the rows or columns box it will automatically create a date hierarchy with Year/Quarter/Month/Date, but since you want week and not quarter, let's create one manually.
First, create a couple calculated columns for week and month. For example:
Month = FORMAT(uptime_downtime[Date], "mmm")
Week = WEEKNUM(uptime_downtime[Date])
Now right-click on the date on the fields, and choose New Hierarchy. It should look like this now:
Now drag the Month and Week columns onto Date Hierarchy and then rearrange them in the appropriate order:
Now you can use that hierarchy in a matrix and use the drill up and down buttons
to get the different groupings: