DAX Year over Year Change in Cash for different Organizations - dax

I am working in PowerBI and would like to accomplish this issue using DAX. I have a table structured as follows:
ID Year Cash
3001 1999 1,200
3001 2000 1,000
3001 2001 2,200
3001 2002 1,900
... ... ...
8500 2014 3,520
I am trying to identify the organizations (indicated by the 'ID' column) that experienced decreases in cash for two consecutive years. There are several thousand organizations, and I have data on every organization from year 1999-2014.

I would first calculate a column for the Prior year Cash values e.g. for [Cash Year-1] as:
=LOOKUPVALUE([Cash],[ID],[ID],[Year],[Year] - 1)
I would repeat for -2.
Then I would use an IF statement to calculate the final column e.g. [Cash Trend]:
=IF(AND([Cash]<[Cash Year-1],[Cash Year-1]<[Cash Year-2]),"Declining for 2 years","Other")

Related

Adding a filter on date with different relations in Power BI

I have three tables based on year
Lecturer table - the year represents the time the lecturer was
recruited
Student table - the year represents the time the student
first registered
Course table - the year represents the time the
course was given
I added a year table with an updating column (based on the Today function) which calculates how many years have passed since that year.
I would like to create different visualizations, each using a slicer/filter on the updating column with a different context. For students I would like to slice according to their academic year, for lecturers I would like to slice according to seniority and for courses, I want to slice according to how recent they are.
Is there an option to define a slicer/filter that chooses the context of the relationship? I am particularly asking about filters and I prefer not to duplicate yearSinceToday column in all my tables.
sample data
studentId
studentName
registrationYear
s1
John
2022
s2
Jack
2023
s3
Jill
2022
lecturerId
lecturerName
lecturerRecruitementYear
l1
Luke
2019
l2
Leia
2018
l3
Lando
2022
courseId
courseName
coursYear
c1.2022
Python
2022
c1.2023
Python
2023
c2.2022
Java
2022
courseId
lecturerId
c1.2022
l1
c1.2023
l2
c2.2022
l3
c2.2022
l2
courseId
studentId
c1.2022
s1
c1.2022
s2
c1.2023
s2
c1.2023
s3
c2.2022
s3
year
yearSinceToday
2018
5
2019
4
2020
3
2021
2
2022
1
2023
0
I would like to be able to ask questions like:
How many courses from year X there are with a lecturer with seniority at least Y?
How many students of the academic year of at least X take each course from year Y?
and so on
Is there an option to define a slicer/filter that chooses the context
of the relationship?
You don't define the slicer this way - you define your measure. Your "yearSinceToday" table is known as a role-playing dimension and you would create active and inactive relationships between it and your other tables. You would then activate the appropriate relationship using USERELATIONSHIP() and have the measure return the appropriate data to filter on.

How to deal with reporting slowly changing dimensions

For a client I am creating a data warehouse in which we have some slowly changing dimensions (or facts if that is even a thing?). For example we want to report the annually recurring revenue (ARR) for subscriptions and we want to have both the currently active and the expired subscriptions in there. So that we can see the ARR over a timeline.
The data we retrieve looks like this:
subscription_id
account_id
ARR
start_date
end_date
1
1
10
01-01-2022
31-03-2022
2
2
20
01-01-2022
31-12-2022
3
1
5
01-04-2022
31-11-2022
So in this case the same account (account_id 1) renewed a subscription at the 01-04-2022. In the report of 2022 we want to see the ARR for all months in 2022. I've looked into slowly changing dimensions, however something I can not really see in that concept is how to report both the currently active license and the history in a dashboard. If we for example want to visualize the ARR in all of 2022 per month in a dashboarding tool we want to see both subscriptions for account_id 1 over the course of the year, not just the currently active one. This seems to be very tricky to do in most dashboarding tools.
To overcome this I've done the following. I created a calendar table with an interval of 1 month and I cross join it with the table above to generate a fact table. The end result would look like:
timestamp
account_id
ARR
01-01-2022
1
10
01-01-2022
2
20
01-02-2022
1
10
...
...
...
01-11-2022
1
10
01-11-2022
2
20
01-11-2022
2
20
This makes it really easy for the user of the reporting tool to filter on a specific month and show the ARR between the dates and over multiple subscriptions. It does however generate a lot of extra data, but at the moment the storage space is not an issue. And it makes it more of a transactional style table, but the ARR is not really a transaction (i.e. it is not really a sold product on a specific date).
My question is: Are there better ways of generating a fact table where the source data contains a date range?

How to create No. Series with day, month and year numbers?

I want to generate No. Series in Business Central in the following format: C220715001
Where 22 is year number as 2022
07 is month number as July
15 is day number as today is 15-07-2022
001 is the invoice number (first generated invoice)
Is it possible to create a No. Series like this without creating 1 line per day?
That would require some development.

Month slicer and filter not working properly on rolling data Power BI

i All.
I have created below measure to reflects always 3 month figures when month slicer is used.
3R =
CALCULATE(COUNT('Order'[Order/ not ordered]),DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH)))
However, when I try to add salesman figures as filter with below formula, and click to month slicer it is directly show just choosen month figures not 3 months.
3R John =
CALCULATE(COUNT('Order'[Order/ notordered])
,DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH),FILTER('Order','Order'[Salesman]="John")))
on below link I have shared a sample for this. there are 2 different table and 1 matrix.
Matrix is named working and 1 of the table is named as "not working properly". not selecting any value on slicer. all data gives same data. however when clicked month slicer not named main table is changing and this is correct. also matrix is correct but table that I am trying to achive is not working.
What i am trying to achive is, 3 month roling data based on customer and salesman. when click for example 1 on month slicer table should give January 2020, December 2019 and November 2019 figures.
https://drive.google.com/file/d/1LoqSiKhHMFn_OioI2RnXOzjcIL9dPRjS/view?usp=sharing
below is the solution. worked for me.
3R John =CALCULATE(COUNT('Order'[Order/notordered]),DATESINPERIOD('Date'[Date],LASTDATE('Date'[Date]),-3,MONTH),'Order'[Salesman]="John"))
just remove filter('order', section and it is ok now.

Multiple Column Groups within matrix for invoice grid

I have to present a matrix or tablix on a report which shows the invoices a customer has had in a given month. It needs to display like this. Where each week is a separate column - managed that - then the row grouping is by weekday e.g. Mon, Tues, that way all the invoices should sort in the same proximity.
When I group by the weekday I do not see all the invoices - there may be multiple invoices on a day. When I group by weekday, invoice number then the grid has four lists for each week but offsets the invoices in the row below each other week
I have honestly been working on this for ages and have tried every grouping an sorting I can think of but cannont get this to work. Tried searches but still cant find anything clear to help.
The Datasource is standard, used both SSAS and DAX separately to get data - that is not a problem as data is correct. Not sure how to display this layout in this form:
Week 1 Week 2 Week3 Week 4
Inv Amount Inv Amount Inv Amount Inv Amount
Mon Inv123 50 Inv130 450 Inv912 5
Inv124 500 Inv133 25
Tue Inv125 75 Inv245 75
Wed Inv126 85 Inv156 95 Inv315 15
Inv316 50
Thur Inv166 10
Fri Inv127 9 Inv451 15 Inv915 15

Resources