Calculate last year group by ID with DAX - filter

I have a table in SSAS Tabular Model like this
Table 1
ID END DATE
1 06/24/2016
1 06/24/2017
1 06/24/2018
2 08/08/2017
2 08/08/2016
3 12/12/2015
I would like to create a Mesure in DAX, in another related Table. The output should be this:
Table 2
ID MAXYEAR
1 2018
1 2018
1 2018
2 2017
2 2017
3 2015
PLEASE !!! WITHOUT USING EARLIER. Because my model is very large, and canĀ“t use this function.

Create a relationship between the 2 tables, assuming that Table 2
contains unique values for ID.
Create a year column from end date
Year = year([END DATE])
After that, in Table 2 create a calculated column with the following code:
MaxYear = CALCULATE(max('Table'[Year]))
Table 2 should look like this

Related

PowerBI - Pivot Rows on Matrix Visualization - Month + 1

I have a dataset in the following format. Notice InitialDate of July
2022 has 1 corresponding row of RollingDate and Churn, June 2022 has
2 corresponding rows, May has 3 etc etc
Which I'm looking to display the results in a table matrix like this.
The issue I'm finding it is that if I just use RollingDate as the
Columns and Churn as the Values, it looks like this
But what I want is this
Add a Rank column to the table as follows:
Rank =
VAR __InitialDate = 'Table'[InitialDate]
RETURN
RANKX(
FILTER( Table , Table[InitialDate] = __InitialDate ),
Table[RollingDate],
,ASC
)-1

Power Query - Merge tables - Sum values with conditions

I'm new to Power Query and I can't figure out how to do the following:
I have two tables
"REQUESTED"
Date
ReqNumber
Client
SKU
ReqQuantity
Jan-01
Z10
1
A
2
Feb-05
Z11
1
A
3
"SENT"
Date
Client
SKU
Quantity
Jan-15
1
A
1
Feb-02
1
A
3
Mar-10
1
A
5
What I want to achieve is that I want to merfe the tables and allow me to filter by date, showing the corresponding amount requested/sent
For Example:
If I filter dates between Jan-01 / Jan - 31
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
1
If I filter dates between Jan-01 / Feb - 28
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
2
Feb-05
Z11
1
A
3
2
If I filter dates between Jan-01 / Mar- 15
I should get the following:
"REQUESTED - SENT"
Date
ReqNumber
Client
SKU
ReqQuantity
SentQuantity
Jan-01
Z10
1
A
2
2
Feb-05
Z11
1
A
3
3
Is this posiible in Power Query?
Thanks!
I believe your question is a simple one that might get passed over because it is simple.
Two tables "Sent" "Requested"...
Merge is under the Home tab.
Set "Requested" as Left and "Sent" as right. Select date for both.
In the Sent column click on the expand icon.

How to complete report derived from another query with zeros or nulls

So, I'm really having a hard time with a report.
I need a report grouped by year. For example, we want to show how many cars are sold per year. So, the report has a column Year, the type/model of the car, and the quantity. However, I also want to show a row with null/zero value, so even when no car of a specific type was sold, I want it to show the row, but with 0.
The problem is, this query is based on a lot of views, which shows each transaction. So, my actual query works fine except it doesn't show a type when none of that type was sold in a year.
When I pivot this report using Oracle APEX, it almost works. It shows all the types, but if I filter per year, then they are gone.
I have all the years I need, but I don't have the data for that year. I take all the data from multiple views with the specifics of the sales. Some of the models/types were not sold in some years, so when I query the report, it doesn't show up, which is expected. For example:
What I get is
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
What I want
//YEAR - MODEL - QUANTITY //
2018 - MODEL 1 - 300
2018 - MODEL 2 - 12
2018 - MODEL 3 - 0
2017 - MODEL 1 - 12
2017 - MODEL 2 - 33
2017 - MODEL 3 - 22
Any ideas?
You can conjure rows, and outer join to them.
with years as (
select add_months(date '1980-1-1', (rownum-1)*12) dt
from dual
connect by level < 5
)
select y.dt, count(e.hiredate)
from scott.emp e
right outer join years y
on y.dt = trunc(e.hiredate,'yy')
group by y.dt
DT COUNT(E.HIREDATE)
------------------- -----------------
01-01-1982 00:00:00 1
01-01-1983 00:00:00 0
01-01-1981 00:00:00 10
01-01-1980 00:00:00 1

Using oracle loop to concatanete strings

I have someting like this
id day descrition
1 1 hi
1 1 today
1 1 is a beautifull
1 1 day
1 2 exemplo
1 2 for
1 2 this case
I need to do a funtion that for each day concatenate the descrtiomn colunm and return the result like this
id day descrition
1 1 hi today is a beautifull thay
1 2 exemplo for this case
Anny ideia about how can i do this usisng a loop in a function in oracle
You need a way of determining which order the values should be aggregated. The snippet below will rely on the implicit order in which Oracle reads the rows from the datafiles - if you have row movement enabled then you may get inconsistent results as the rows can be read in different orders as they are relocated in the underlying datafiles.
SELECT LISTAGG( description, ' ' ) WITHIN GROUP ( ORDER BY ROWNUM ) AS description
FROM your_table
GROUP BY id, day
It would be better to have another column that stores the order within each day.

how to write a oracle sql query order by two columns

I have a table include two columns, year and month, I want get a unique result that order by year and month.
example:
y m
2013 12
2012 1
2013 4
2012 3
I want get
y m
2013 12
How to write the SQL query. thanks.
select * from table where y = 2013 and m = 12;
Do you want this ?

Resources