Data for the maximum date for an employee - obiee

I need to to get the value on the maximum date for a particular employee.
Eg: I select 30/06/2017 as the date. But for the employee the Score is 0 on 30/06/2017. But on 28/06/2017 he has a value of 94. So, I need to show this value in my report.
Could anyone help me with this?

Found the solution Write filters as TOPN(Date, 1 by Employee) is equal to/is in 1, Score not in (NULL, 0) and Date is prompted. This works.

Related

Calculate the sum grouped by 2 other columns

Please I really need your help on this, Hello,
I need to create a measure using DAX that has the sum of the qty, I should take the max date of the table that is between two other dates (Date Slicer) based on the column name, For example, if the selected date of the slicer is between 24/6/2020 and 20/3/2021, I need to calculate the total (sum of the qty of each name 'column' where it's date is the max date that is less then the max selected date
So as you can see in the figure the total should be 50+129+3(For that selected date)
Quantity =
VAR _maxdate =
MAX ( 'Date Table'[Date] )
RETURN
SUM ( CALCULATE([Qty], 'Fact Table'[Date] <= _maxdate )
The CALCULATE function in DAX is very powerful. Essentially, you can pass filter criteria into it to create aggregations. In this case, it sounds like you want to sum [Qty] when the date is < the max date.
Since your table visuals aren't automatically updating, you also may not be implementing a date table correctly.

Small detail when using this function in Google Sheets

Small detail when using =INDEX($A$8:$A$11;MATCH(MAX(SUMIF($B$8:$B$11;$B$8:$B$11));SUMIF($B$8:$B$11;$B$8:$B$11);0))) If the values in column B are all different it returns the correct date value, but if two identical values in column B coincide in different dates then it returns the date of the first value; it does not return the correct date and it keeps the first one that has the repeated value.
Any idea?
p.s This question can be added to this post
Even more easier way:
On E2 Try this =TRANSPOSE(INDEX(QUERY(A1:B," select A, sum(B) group by A Order By sum(B) Desc "),2))
and format the date and currency accordingly.
You can do that easily and differently to get:
1 - Make a helper table to get unique dates, You can use two ways
a) - Use SUMIF Function to get the sum of Expenditure in each unique date Like so =IF(D2="",,SUMIF($A$2:$A,D2,$B$2:$B)) and drag it down.
b) - By using QUERY Function =QUERY(A1:B11," select A, sum(B) group by A Order By sum(B) Desc ")
2 - to get SUM BY DATE OF HIGHEST EXPENDITURE: =MAX(E2:E)
3 - to get DATE BY HIGHEST EXPENDITURE: =INDEX($D$2:$D,MATCH($H$3,$E$2:$E,0),1)
Make a copy of this sheet "make it yours."
Hope that answerd your question.

Oracle SQL exlusion constraint

I am looking for an Oracle constraint that will exlude all rows in a table that have already been updated for a given year. For example, a given Id field of "123456789_2019_blah" includes the year 2019 as part of the Id. Each day a query will check the table to see if a given year is missing in the Id, such as the year 2020 in "123456789_2020_blah". If 2020 does not exist, a second row will be inserted with the value "123456789_2020_blah"
-----------------------
Id
-----------------------
1: 123456789_2019_blah
2: 123456789_2020_blah
Going forward, any other time the query runs it should never return rows for Id "123456789_2019_blah" or "123456789_2020_blah". The following year will repeat with 2021, etc. (Assume that field Id is the only field available for the constraint)
I tried using REGEXP_INSTR to check its length but this still returns the 2019 row because there will always be one true result. I also tried group by having with the same result.
where (REGEXP_INSTR(Id,'*_2019_*') > 0 and REGEXP_INSTR(Id,'*_2020_*') = 0)
The solution was to create a function that returns 0 if the latest year does not exist.
Return 0 if the latest year does not exist
REGEXP_INSTR(name,'*_' || i_year || '_*') > 0

How to get the difference between the values selected by slicer?

I am new to Power BI and currently I am working with table visulaizations and slicers.
My data is as follows
Student table:
Date table:
Exam table:
The relationships within the table are as follows:
I want an output like the image shown below, I would like to create 2 table visuals that can be filtered on Student Name, Classroom and also have slicer on 2 dates. I need to compute minimum score. The user must be able to select 2 dates at a time on the slicer, the first date selected on the slicer should be attached to my 'Min Score at date1' and second date selected on the slicer should be attached to my 'Min Score at date2', and the third column 'Difference in Score' must be able to calculate the difference between the Min Score at date1 and Min Score at date2.
Similarly I also want to calculate the average minimum score too
Please let me know how to proceed or what alternative formula or query or method should I apply to get the desired result.Thanks!
Before I start, let me mention that this example was done in SSAS so it may need some tweaking in PowerBi but the logic is identical nonetheless.
First create a clone date table and call it something else e.g. 'Compare Date'. Next, create an inactive, one to many relationship between the 'Compare Date' and your 'Fact' table, see the image below, in this case I am joining on [Year Month], you will need to adjust to fit your needs:
If you are unsure how to do this, just right click on the new table and select the create relationship option, ensure that the relationship is like the image below:
Once this has been done, right click on the 'relationship' and mark it as inactive.
Now that you have the new date table and the relationships set up, I want you to create a few DAX measures:
Min Date 1 = Min('Student Table'[Score])
Min Date 2 = CALCULATE(Min('Student Table'[Score]), ALL('Dates'), USERELATIONSHIP('Compare Date'[Date], 'Fact'[Date]))
Avg Date 1 = AVERAGE('Student Table'[Score])
Avg Date 2 = CALCULATE(AVERAGE('Student Table'[Score]), ALL('Dates'), USERELATIONSHIP('Compare Date'[Date], 'Fact'[Date]))
Delta Min = [Min Date 2] - [Min Date 1]
Delta Avg = [Avg Date 2] - [Avg Date 1]
These measures will calculate exactly what you need and can be filtered independently via two date slicers tied to each date table. The rest is just busy work.
I hope this helps.

Oracle query to fetch the previous value of a related row in same table

I have a table Student which has name and ratings year wise.
Name Year Rating
Ram 2016 10
Sam 2016 9
Ram 2014 8
Sam 2012 7
I need to find the previous rating of the employee which could be last year or some years before.
The query should return below results
Name Cur_rating_year_2016 Prev_rating
Ram 10 8
Sam 9 7
Below is the script for insert and create
Create table Student (name varchar2(10), year number, rating number );
insert into student values('Ram' ,2016 ,10);
insert into student values('Sam' ,2016 ,9);
insert into student values('Sam' ,2012 ,7);
insert into student values('Ram' ,2014 ,8);
Is there a way to achieve this using select query?
Use LAG analytical function https://docs.oracle.com/database/122/SQLRF/LAG.htm#SQLRF00652
LAG is an analytic function. It provides access to more than one row
of a table at the same time without a self join. Given a series of
rows returned from a query and a position of the cursor, LAG provides
access to a row at a given physical offset prior to that position.
For the optional offset argument, specify an integer that is greater
than zero. If you do not specify offset, then its default is 1. The
optional default value is returned if the offset goes beyond the scope
of the window. If you do not specify default, then its default is
null.
SELECT stud_name AS name,
r_year AS year,
r_value AS rating,
lag(r_value, 1, NULL) OVER(PARTITION BY stud_name ORDER BY r_year) AS prev_rating
FROM stud_r
ORDER BY stud_name;
Try as:
SELECT A.NAME,A.RATING,B.RATING FROM
STUDENTS A INNER JOIN STUDENTS B
ON A.NAME=B.NAME
WHERE A.YEAR='2016' AND B.YEAR<>'2016'
ORDER BY A.NAME ASC

Resources