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

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
)

Related

How to build relationship based on range of dates (periods) in Power BI

I'm trying to figure out the best way to build a relationship from a table that has records in a daily format (one record represents a single date) to a table that contains records in a date-range format (one record has a start-date and end-date, consequentially representing a period or range of dates).
Since my actual datafiles contain work-related information, I created 2 demo tables that contain dummy data that reflects the date columns in question.
Here is my DailyDate table
Here is my DateRanges table
Here is the current model view
I would like to be able to have a relationship built between the tables so that if I were to have 2 tables/matrices in the Report view, with one table showing the Daily Date Data and the other table showing the Ranged Data Data, I would be able to select a record in the Daily table and Power BI's highlight functionality would filter the records in the Ranged table so that only date ranges containing my selected date appear, and vice-versa (if possible).
For example, referencing this screenshot, if I were to select index 0 in the 'Daily Data Data' table, the 'Ranged Date Data' table should be filtered to only show records with index of 0 in the other table. If I were to select Index 2 (01/03/2022) in the Daily Date Data table then the Ranged Date Data table should be filtered to only show indices (0, 1).
In the model view, when trying to build this relationship, I can create a relationship from DailyDates.Date to DateRanges.StartDate and then from DailyDates.Date to DateRanges.EndDate; however, only a single relationship can be active so the highlight and slicer functionality will not give me the results I'm looking for.
As you can see from this demo, the datasets are small; however, my actual datasets contain around 50 million records in the Daily table and 10+ million records in teh Ranged table, so I'm hoping there can be an efficient method of getting this functionality that will not be too much of a load on memory.
Any advice into how to accomplish this would be greatly appreciated.

Create a pivot table in Power BI with dates instead of aggregate values?

I have a table of companies with descriptive data about where we are in the sales stage with the company, and the date we entered that specific stage. As can be seen below, the stages are rows in a Process Step column
My objective is to pivot this column so each Process Step is a column, with a date below it, as shown in excel:
I tried to edit the query and pivot the column upon loading it, but for the "aggregate value" column, no matter which column I use as the values column, it results in some form of error
My advice would be not to pivot the table in the query and use measures to get dates that you want. The benefit of not doing so is that you are able to perform all sorts of other analytics. For instance, Sankey chart would be hard to do properly with pivoted table.
To get the pivot table you are showing from Excel, it's as simple as using matrix visual in Power BI and putting Client code in rows and Process Step in Columns, then Effective date in values.
If you need to perform calculations between stages, it's also not too difficult. For instance, you can create a meausure that shows only dates at certain stages, another measure for another stage, and so on. For example:
Date uploaded = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Upload"))
Date exported = CALCULATE(MAX(Table[Effective Date]), FILTER(Table, Table[Process Step] = "Export"))
Time upload to export = DATEDIFF([Date uploaded], [Date exported], DAY)
These measures will work in the context of client and assuming there is only one date for the upload step (but no Process step in rows or columns). If another scenario is needed, perhaps a different approach could be taken.
Please let me know if that solves your problem.

Getting date for calculation

I am a new user of Power BI and I was wondering if it is possible to calculate the date difference that is present in two different tables but they both are connected to the third table in which I want to create a measure or a column using dax to calculate date difference:
The columns marked in red are dates and I want their difference to be calculated in the assumption table. I used the month number to build the relationship between these tables.
You can use a Measure as below-
date_diff =
DATEDIFF(
RELATED(d_nl[notification]),
RELATED(d_fc[file_closure_date]),
DAY
)
To know about other Intervals rather than DAY, you can visit Here.

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 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/