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

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/

Related

Power BI Divide two measure from different tables and show in a graph with time

I have two tables, Table one has daily data, Table two has weekly data. I've created a start of week column in Table 1 to get weekly data. Data is as shown below :
I want to create a table where I can divide these two measures. Both measures are counts in a week. I want to present this in a line/bar chart with time at the x-axis. Right now when I use the Date of Table 1, My measure 2 takes the overall count as the date of table 2 is not present and vice versa. I was thinking of creating a new Calendar table but I'm unable to get these measure values in that table.
I tried creating a custom calendar table but I'm not getting the desired result. I'm getting correct values from table 2 but no values from table 1. I feel the problem is because table 1 has duplicate date values.
Table 1 actual data before consolidation:Measure is the count of case numbers
I think you need a slight paradigm shift in your thinking, potentially.
Rather than looking for a way to create a third table from two other tables, what you should do is create a relationship between the two tables to make a rational description of how you want these tables to work, and then write the DAX on top of it.
So, in your case, you describe one table having daily data, and the other having weekly. The intermediary calendar table would be a daily calendar, where each day (row) knows the end of week date.
You would then create a relationship from your daily table to the calendar table based on day, and create a second relationship to your weekly table based on end of week date. (assuming bi-directional filtering)
You could then create a measure:
myRatio = DIVIDE(SUM(DailyTable[value]), SUM(weeklyTable[value])
In your chart, you can then show the daily value as a fraction of the weekly value by using the 'Day' field from the calendar table, or you could show the ratio of the complete week from the daily table to the weekly total in the weekly table by using the end of week date in the chart.
If what you truly need is a 3rd table, then you could use the SUMMARIZE() function on this 3 table set to do the summarization into a 3rd table using the same principle.
myNewTable =
SUMMARIZE(calendarTable
,calendarTable[End of Week Date]
,"My Ratio" //the name of the field you want to create
,[My Ratio] //the formula to describe what goes in the field
)

Unable to connect Fact Tables to Calendar Table

In all my fact tables, I have separate columns for quarter, and year.
I also have a calendar table with columns for Date, Quarter, Year, Month Name etc.
I want to connect both columns from my fact tables to the calendar table but PowerBI wont allow me. It also tells me that I have cardinality many-to-many since I have multiple records for the same Year and Quarter in both the Calendar and Fact tables.
My goal is to have a report consisting of slicers / dropdowns for Yearand Quarter, so that I can see how my metrics performed over time.
I'd like to know how to best handle such instances. How should I design my data model that will allow me to filter my reports by quarter and year.
Really appreciate your help!
The fact tables need to have an value that is unique in the calendar table, so the corresponding row from the calendar table can be identified.
In the most common scenarios, the fact table will have a transaction date column and the calendar table has a date column. In the calendar table, the date column has only unique values, whereas the columns for Month, year, etc, contain duplicates, of course.
In the Fact table, there may be many records with the same date, but each date can be connected to just ONE single entry in the calendar table.
Your screenshot does not show any date columns in the fact tables.
You don't have to use a date, but you need a key column in the Fact tables that can be linked to a column with unique values in the Calendar table.
If you add a combination of Year-Quarter to all tables, Fact AND Calendar, then you can use these in the relationship and the error will go away

How to use a date slicer to filter two visualizations of two different columns in the same table in PowerBI

I have searched for this query and attempted to implement some solutions i've found but i've not been able to apply the solutions to my problem so i'm hoping you can help.
We have a table with data, including "created" and "submitted" date columns. I'm wanting to use one slicer to individually show how many results for items created on the selected date, and items submitted on the selected date.
Any help would be great.
Thanks in advance.
You will need a calendar table for this to work correctly as you will have to have a relationship between your data table and the calendar.
Using this example
In the above table, there is Order and Shipping Date, with a quantity column.
The calendar table is connected by the data column to the Order and Shipping Date. As you can only have one active relationship between the table, one is set as inactive. In this case the Shipping Date is Inactive.
So if I select a filter of 07/01/2018 on the Order data it will not show the quantity of items shipped, just the items ordered as it will filter out those rows.
In the above image, the table has been filtered using the active relationship and it only shows Orders for the 7th and Shipped on the 12th as that is what is in the table (Visual on the right)
So you will need two measures, one using the active and one using the inactive.
So you count the Orders as normal, and the Shipped with a relationship modifier:
Total Orders = SUM('TableName'[Quantity])
Total Shipped = CALCULATE(SUM(Billing[Quantity]), USERELATIONSHIP(Billing[Shipping Date], 'Calendar'[Date]))
USERELATIONSHIP forces the Total Shipped to ignore the filter context on active relationship and use the inactive one.
So it should return Shipped 366, Ordered 353 for the 7/01/2018. You'll need to use the calendar table in your visuals to drive the dates, not the dates in your data.

power bi: how to add common date slicer that filters on two or three charts data based on date

How to add common date slicer which will filter two or three charts data based on date column of those charts
i have tried to create a date table and applied relation and when i used date slicer it is showing empty data even though data is there in the mentioned dates range
I need to create a common date filter for three charts present in power bi report. three charts using three different tables and with different columns we dont have any relation between them. But all three tables have a date column so Now i need to create a common date slicer so that i can filter using that and results should be generated
slicer should filter data of multiple charts.
The best suggestion is to build your own date table in Power BI. You can take a look at this post here for more details.
Now you might end up having to normalize the dates in your existing tables as well to ensure that you are linking all tables on a common date type.

Creating Date Relationship in Power BI for Slicers

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.