Add Missing Dates for Multiple Values - powerbi

I seem to be having issues adding missing dates to a table - It is pretty straightforward if I am doing it for one individual item but the challenge comes when trying to add missing dates for multiple items. I do have a standard date table also.
This is a data sample I currently have...
Date
Product
Amount
2/1/2022
Item A
2.74
2/1/2022
Item B
3.13
2/3/2022
Item A
2.82
2/3/2022
Item B
3.21
2/5/2022
Item A
2.77
2/5/2022
Item B
3.21
This is the expected solution...
Date
Product
Amount
2/1/2022
Item A
2.74
2/1/2022
Item B
3.13
2/2/2022
Item A
NULL
2/2/2022
Item B
NULL
2/3/2022
Item A
2.82
2/3/2022
Item B
3.21
2/4/2022
Item A
NULL
2/4/2022
Item B
NULL
2/5/2022
Item A
2.77
2/5/2022
Item B
3.26

Related

DAX Measure not Filtering Results as it should be (when sliced by another attribute)

I have a dataset of employees working on month-to-month basis, 
The dataset looks something like this, 
Date
Emp Code
Project Code
Allocation
7/1/2022 0:00
1
A
0
8/1/2022 0:00
1
A
0
9/1/2022 0:00
1
A
1
10/1/2022 0:00
1
A
1
11/1/2022 0:00
1
A
0.2
12/1/2022 0:00
1
A
0
7/1/2022 0:00
2
B
1
8/1/2022 0:00
2
B
1
9/1/2022 0:00
2
B
1
10/1/2022 0:00
2
B
1
11/1/2022 0:00
2
B
0.2
12/1/2022 0:00
2
B
1
I have a Slicer for Date Range from which the user can select any date range and data will be filtered accordingly. 
I have a Matrix Visual that shows allocation of employees month-wise. There is an additional Filter is applied on this Matrix visual, that it only shows those employees which have been allocated (have allocation > 0) on all months being filtered. For example, If I am filtering from August to December, then only the records which have allocation greater than 0 FOR ALL THE MONTHS (August to December) will be shown. I have also attached two examples below to demonstrate this, 
(As only the employee with Emp ID = 2 was allocated on all the months from July to December, so his record is shown only) 
(As both the employees with Emp ID 1 and Emp ID 2 are allocated in ALL THE MONTHS from September to December (filtered range of date), so their records are shown.
This is the measure that I am using currently in this Matrix Visual to filter out the employees which don't have allocation > 0 for all the months being filtered, 
Employee Allocated All Months Boolean =
Var _count =
CALCULATE(
DISTINCTCOUNT('Calendar'[Month]),
FILTER(
ALLSELECTED(Competency),
Competency[Emp Code] = MAX(Competency[Emp Code])
)
)
Var _total =
CALCULATE(
DISTINCTCOUNT('Calendar'[Month]),
ALLSELECTED(Competency)
)
RETURN
IF(_count = _total, 1)
My problem comes in when I filter the data table, i.e., when I filter the Project. So, right now, Emp ID is working in Project B and Emp ID 2 is working on Project A. When I filter the Report by Project A, my dataset will now contain records of only Emp ID = 1. 
And now, it starts giving incorrect results. That is, when I am slicing by the Date (July to December), it should show me Blank (that is, no records) because no Emp matches the Condition that I am applying. However, it instead shows me Emp ID 1 and only shows the "three months" in which it was allocated (neglecting the other months altogether). That is what I do not want it to do. 
I have tried to fix this in all the ways I could, but still couldn't do it. I tried to use "ALL" with the table in the Calculate but it didn't work for me, I don't know why. 
Can anyone help in resolving this issue? Thanks a lot in advance.
If you would like to use the Power BI File, then you can download it from here: https://drive.google.com/file/d/1X31vAnPlS7gnkHEfcveYpg_wQwE1sKLh/view?usp=sharing

Filter two tables based on dates and sum the result in power bi

I have a problem summing the result of two tables. The first table has the sold quantities. The second table has the forecasted quantities. Both tables are linked to a calendar table (not represented). The third table has cut-off dates for both products.
Exported:
Product
Date
Quantity
A
1/1/2022
10
A
2/1/2022
10
A
3/1/2022
10
B
1/1/2022
5
B
2/1/2022
5
B
3/1/2022
5
Forecast:
Product
Date
Quantity
A
1/1/2022
20
A
2/1/2022
20
A
3/1/2022
20
A
4/1/2022
20
B
1/1/2022
15
B
2/1/2022
15
B
3/1/2022
15
B
4/1/2022
15
Cut Off Dates
Product
CutOffDate
A
2/1/2022
B
3/1/2022
The first goal is to filter both tables with the cut off date, getting from the first table and the product A & B:
Product
Date
Quantity
A
1/1/2022
10
A
2/1/2022
10
B
1/1/2022
5
B
2/1/2022
5
B
3/1/2022
5
Those dates are <=2/1/2022 for product A (The cut off date for product A) and <=3/1/2022 for product B (The cut off date for product B).
After that I need the same for table 2, but considering the dates after the cut off date:
Product
Date
Quantity
A
3/1/2022
20
A
4/1/2022
20
B
4/1/2022
15
Next, I need to mix both tables to obtain:
Product
Date
Quantity
A
1/1/2022
10
A
2/1/2022
10
A
3/1/2022
20
A
4/1/2022
20
B
1/1/2022
5
B
2/1/2022
5
B
3/1/2022
5
B
4/1/2022
15
Finally, my goal is to have the following result:
Date
Quantity
1/1/2022
15
2/1/2022
15
3/1/2022
25
4/1/2022
35
Thanks in advance!
I tried to do it using max for the dates, but I can't keep the Product context filter, causing that my table is only filtered by my maximum cut off date (3/1/2022)
You can use this Calculated Table to get your desired result:
Result =
VAR _tbl =
UNION(
FILTER(
Exported,
Exported[Date] <= RELATED('Cut Off Dates'[CutOffDate])
),
FILTER(
Forecast,
Forecast[Date] > RELATED('Cut Off Dates'[CutOffDate])
)
)
RETURN
GROUPBY(
_tbl,
[Date],
"Quantity", SUMX( CURRENTGROUP(), [Quantity])
)
but make sure you have a relation between your 3 input tables on the Product columns

How to create a visual showing top 3 employees with highest sales for every date in a bar chart?

I have a table with the Date, Analyst Name, and Quantity of tickets resolved. What I want to create is a visual with a stacked bar chart for every date showing the top 3 analysts with the highest quantities of tickets resolved for each day.
I have tried using the TOP N filter but it filters every analyst except the 3 with the highest number of tickets resolved overall. But I want for each date.
You could use a rank measure.
Considering the following table with sample data:
Date
Analyst Name
Quantity
2021-01-01
A
5
2021-01-01
B
10
2021-01-01
C
15
2021-01-01
D
20
2021-01-02
A
42
2021-01-02
B
32
2021-01-02
C
22
2021-01-02
D
12
2021-01-03
A
15
2021-01-03
B
5
2021-01-03
C
21
2021-01-03
D
30
You can write a measure like this:
Rank =
RANKX (
CALCULATETABLE (
'Table',
-- remove the filter an Analyst Name to only keep grouping by Date
REMOVEFILTERS ( 'Table'[Analyst Name] )
),
-- CALCULATE needed here for context transition
CALCULATE (
SUM ( 'Table'[Quantity] )
)
)
In your report just pull this measure into the filter panel and configure it like this:
The result will then look like this:

DAX to show rows with null date values in selected date slicer range

I have a typical scenario as below.
I have a student table and it contains four columns as below :-
1.StudentID
2.StudentName
3.LastAttendanceDate
4.StudentType
Now there are some null values in the date column LastAttendanceDate.Is it possible to use a date slicer to show these values of the students who have LastAttendanceDate column value as null? In simple words: Say you are a student who went to a school on Monday, Tuesday and Friday and you were absent on Wednesday and Thursday so here Wednesday and Thursday are the days where you were absent in the week and we need to display these records in the table visualization.
My excel Input data:-
StudentID StudentName LastAttendanceDate StudentType
100 Mary 02-05-2011 10:45 Fulltime
100 Mary Fulltime
100 Mary 04-05-2011 12:45 Fulltime
100 Mary 06-05-2011 15:45 Fulltime
100 Mary Fulltime
100 Mary 08-05-2011 19:45 Fulltime
100 Mary 09-05-2011 12:45 Fulltime
101 John 02-05-2011 10:45 Part Time
101 John 03-05-2011 11:23 Part Time
101 John 04-05-2011 10:45 Part Time
101 John 06-05-2011 15:49 Part Time
101 John Part Time
101 John 08-05-2011 19:45 Part Time
101 John 09-05-2011 12:45 Part Time
so here I need to dynamically find in the week/month range or any dynamic date range say from date range 02-05-2011 and 08-05-2011 or 02-05-2011 and 09-05-2011 or even 06-05-2011 and 09-05-2011, the students who were absent and show it in my table visualization.
Can anyone provide an approach or any helpful DAX? Appreciate all the help
My present visualization looks like this :
I want to show the students who were absent in the given time range as selected in the date slicer.
so if I slide the date slicer as per minimum and maximum ranges, it should show all the rows of students who were absent or with null values for Last Attendance Date column in those time range.
Kind regards
Sameer

Querying Historical Data to get Month End Data

We have a history table that keeps all instances of a record, and flags which is the current record and when it is changed - here is a cut down version for it
CREATE TABLE *schema*.hist_temp
(
record_id VARCHAR
,record_created_date DATE
,current_flag BOOLEAN
,value int
)
INSERT INTO hist_temp VALUES ('Record A','2018-06-01',1,1000);
INSERT INTO hist_temp VALUES ('Record A','2018-04-12',0,900);
INSERT INTO hist_temp VALUES ('Record A','2018-03-13',0,800);
INSERT INTO hist_temp VALUES ('Record A','2018-01-13',0,700);
So what we have is Record A, which has been updated 3 times, the latest record is flagged with a 1 but we want to see all 4 instances of the history.
Then we have a dates table which holds, among other things, month end dates:
SELECT
calendar_date
,trunc(month_start) as month_start
FROM common.calendar
WHERE
calendar_year = '2018'
and calendar_date < trunc(sysdate)
ORDER BY 1 desc
Sample data:
calendar_date month_start
2018-06-03 2018-06-01
2018-06-02 2018-06-01
2018-06-01 2018-06-01
2018-05-31 2018-05-01
2018-05-30 2018-05-01
2018-05-29 2018-05-01
2018-05-28 2018-05-01
2018-05-27 2018-05-01
2018-05-26 2018-05-01
2018-05-25 2018-05-01
etc
Required results:
I would like to be able to display the following - show the month start / end position for Record A for 2018
record_id, month_start, value
Record A, '2018-06-01', 1000
Record A, '2018-05-01', 900
Record A, '2018-04-01', 800
Record A, '2018-03-01', 700
Record A, '2018-02-01', 700
I am trying to write this query, I have something but know this is wrong as the value is summed up wrongly, please can someone help out ascertain how to get the correct values?
Try:
SELECT
record_id,
date_trunc('month', record_created_date)::date AS month_start,
value
FROM hist_temp
Output:
Record A 2018-06-01 1000
Record A 2018-04-01 900
Record A 2018-01-01 700
Record A 2018-03-01 800