Getting date for calculation - powerbi

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.

Related

How to add same measure used in different vizualiztions. power Bi?

I have a measure [expense]. I have two filters filter1(current year expense) and filter2(prev year expense)
I have created two table in a Power Bi report, and used the same measure expense in them both of them such that,
The first table ignores filter 2(prev year expense) and only filter1(current year expense) is applied
The second table ignores filter1 and only filter 2 accepts.
Basically I want to have Current year and prev year expense in two separate tables. This I am able to achieve quite easily, using edit interactions.
But the problem is I also need a third table which should give the result as the total of the two tables. Since I am using the same measure in both the tables, how can I achieve this.
Note:: My total table total summation should change based on filters selected .
Basically table3=table1+table2.
Try something like this. Filter the third table with filter1(current year expense). I do not see better solution within your report logic.
CALCULATE(
[expense]
,tbl[Year] In {SELECTEDVALUE(tbl[Year]),SELECTEDVALUE(tbl[Year])-1}
)

Dynamic filtering based on selected value in slicer in Power BI

I am trying to create a calculated table where the data is being taken from another table and calculating the average based on the username, total average and variance between the 2 of these columns.
To create a table, I used the below DAX in Power BI which calculated the average based on the username.
scanner_speed_average_calculation =
SUMMARIZE(scanner_speed
,scanner_speed[user_name]
,"Average"
,AVERAGE(scanner_speed[order_processed]))
To calculate the group_average I used the below DAX:
group_average =
SUMMARIZE(
scanner_speed
, "Group Avg"
, average(scanner_speed[order_processed]))
And finally to calculate the variance, I used this query:
Variance = scanner_speed_average_calculation[Average] - scanner_speed_average_calculation[group_average]
Below is an outcome of these calculations.
I want to be able to make these calculations dynamic based on the selected value from the date. The table where I am taking these calculations do have the date value. I want to be able to use date range in slicer and I want these values to change based on the selected date range. I tried few things with Filter, Selectedvalue but I am not sure if I used them correctly.
Below is a main table where I took all these calculations from.
Below is a visual of where I want to group_average and variance. I want to be able to use date range and these columns should change accordingly.
Any idea or help will be appreciated. If possible then please put the entire formula. I am still a newbie in the world of DAX. Thanks in advance
power bi file
If you want a calculation to depend on a slicer, you need a Measure, not a calculated column or calculated table. Calculated columns and calculated tables are generated on refresh and physically stored in your model, so the slicers can filter them, but the slicers can't change the value of the calculations.
Measures are not persisted, but are calculated as needed based on changes to filters and slicers.
If you simply add add a measure
AverageOrdersProcessed := AVERAGE(scanner_speed[order_processed])
and put that on a visual that groups by user_name, you will get a the AVERAGE(scanner_speed[order_processed]) for each `user_name'.

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
)

Power BI DAX Dynamic Calendar

I am trying to create a Dynamic Table in Power BI.
I have my set of data, and basically I want the calendar to pick up the minimum date and the maximum date from my table, but only if the maximum date is not the month of today. If the maximum date is the month of today, then it should ignore it and the calendar should be created with the max date of the previous month.
I started the formula, but can't seem to continue it. Any ideas?
Calendar_= CALENDAR(MIN('Table1'[Date]),IF(MONTH(MAX('Table1'[Date]))=MONTH(TODAY()),date(YEAR(MAX('Table1'[Date])),.....
See if this post helps: https://community.powerbi.com/t5/Desktop/Dynamic-table-or-on-fly-table-generation-via-DAX/m-p/434397#M200275. If not, I would simplify by creating some additional calculated columns or measures and then reference those instead of one nice big formula

How can I get the number of days by month from a slicer in Power BI?

I just want to select a range of days in a slicer and show in a table the number of days for each month/period (month-year).
I used DAX to create a table with the information I need and I don't have problems with the periods (first column), it changes dinamically, the problem is the column "Days" (second column) because it's always showing the total number of days for each month.
Here my DAX code
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Here the result
What I expect is:
2 for april, 31 for may, 1 for june
This is an issue with execution order.
SelectedPeriods = GROUPBY(DimDate;DimDate[Period];"Days";COUNTX(CURRENTGROUP();DimDate[DateKey]))
Generates a calculated table. These are calculated when the data model is refreshed and stored in it. They are not refreshed each time a connected dimension is changed within a dashboard.
In your case, while changing date filters may hide rows from this table the number of days remains fixed at the number calculated initially when there was no filter context on the data i.e. counting all days in the month.
If you want the result to change then you need to use a measure instead of a calculated table. Measures react to the current filter context within the report and so will adjust their output each time a slicer is changed.
The needed measure will depend on your model but might be something as simple as:
CountOfDays := CountRows(DimDate)