I have a table with customers' SSN, account number, purchase date, and max purchase date (the most recent purchase date for SSN, across all the accounts). Customers can have multiple accounts. I know how to create a measure the calculate the distinct count of all the accounts that haven't been active since a certain date (6 months, 18 month, 24 months)..
I would like to create a measure or a calculated column to give me the following information.
when users select the date from the slicer (say 6 months) the chart shows the count of the accounts that have not made a purchase in 6 months, the users also want to have a drop down slicer("Yes", "No") to indicate if the SSN had activities under other accounts. i.e. if the max purchase date is greater than the value from the date slicer.
the table structure looks like this:
SSN AccountNumber LastPurchaseDate MaxPurchaseDate
123-45-5678 9876 8/2/2018 9/4/2019
123-45-5678 6398 9/4/2019 9/4/2019
135-65-4321 2233 6/6/2019 6/6/2019
Best way here would be if you add a custom column with the time difference (in the query designer):
= [MaxPurchaseDate] - [LastPurchaseDate]
Now you have something like this:
SSN AccountNumber LastPurchaseDate MaxPurchaseDate DateDiffDays
123-45-5678 9876 9/2/2018 9/4/2019 2
123-45-5678 6398 9/4/2019 9/4/2019 0
135-65-4321 2233 6/12/2019 6/6/2019 6
You can add another column which acts as filter for your 6 months, 18 month, 24 months (convert the DateDiffDays into months).
The following measure counts the accounts:
=Distinctcount('YourTable'[AccountNumber])
If you filter now by your 6 months, 18 month, 24 months column the measure gets after every filtering calculated again and you get your result.
Related
tldr: I have two tables linked with two relationships, how do I calculate using both?
Hi, I am building a report on a fictional phone company. The data is stored in mongodb with the following format
User Account {
_id : unique account ID
other account details : [...]
yearly records : Array [ Yearly Record]
}
Yearly Record {
year num : ex 2022
monthly records : Array [Monthly Record]
}
Monthly Record {
month num : ex 5 for may
purchased minutes : minutes purchased this month
daily records : Array [Daily Record]
}
Daily Record {
date : date
consumed minutes : minutes used today
}
In this scenario, the minutes do not expire, each month you choose the amount you want to top up. The tables of interest are the monthly and daily tables. PowerBI fuses all user accounts in a single table. I'll omit some things but it looks like:
Monthly Records
_id purchased minutes monthly records idx yearly records idx
account id 100 position in monthly record array same principle
-----------------------------------------------
Daily Records
_id used minutes date daily records idx monthly records idx yearly records idx
account id 5 2022-10-31 ... ... ...
All tables are linked using _id in the modeling. For daily and monthly, the active relationship is the month idx. But since the tables are in the db, the month idx repeat so the relationship is many to many.
I havent found a way to filter out only the monthly details for only one user. SO if I were to put id and monthly purchase in a table, each user contains the reords of all users (see below)
Monthly Records
_id purchased minutes monthly records idx yearly records idx
1 100 0 0
2 200 0 0
Table:
id year month purchased min
1 2022 jan 100
1 2022 jan 200
2 2022 jan 100
2 2022 jan 200
The right months line up but the records are treated as duplicates (so if in feb 1 bought 300, we'd see feb 300 for both 1 anbd 2). I would almost need two active relationships on both the month idx and the id
How do I create a measure that is affected by both relationships? For instance if I chose id =1 and year + month = jan 2022 in slicers I should get only 100
Is this even possible in dax? I tried playing around with filter by id to no avail. In python there would be ways but then we deal with script visuals
My end goal is graphing minutes balance over time with
measure = bought - consumed
we'd see spikes at beginnings of month and the nline slowly go down as muinutes are used
I know you cannot outright define two active relationships but are there ways to deal with data as such?
I have two tables in Power BI as follows:
COUNTRIES
COD COUNTRY
1 BRAZIL
2 ARGENTINA
3 CHILE
4 BRASIL
5 COLOMBIA
6 ARGENTINA
7 URUGUAI
SALES
COD DATE
1 2021-01-02
2 2021-10-01
3 2019-09-04
1 2018-07-05
7 2019-04-10
There's a relationship between the two tables, on the COD column.
I need to count how many countries (column "COUNTRY" from the table "COUNTRIES") have a status CHURN. It's considered CHURN when their latest order from the table "SALES" is more than 180 days, using today as a reference.
I know that I need to group by the MAX date per country, do a DATEDIFF, and then do a COUNT. I've tried using ALL and SUMMARIZE, but I haven't found a way to solve this problem.
Are you able to add a calculated column to store the max sales date for each country in your COUNTRIES table? Either in Power BI or directly in your database. If so, here's one solution with 2 steps.
Create a MaxSalesDate column in your COUNTRIES table. DAX for a calculated column below:
MaxSalesDate =
VAR COD = COUNTRIES[COD]
RETURN MAXX(FILTER(SALES, SALES[COD] = COD), SALES[DATE])
Create a measure that counts the number of MaxSalesDate values that are older than 180 days old:
CountCHURN = COUNTX(COUNTRIES, IF(DATEDIFF(COUNTRIES[MaxSalesDate], TODAY(), Day) > 180, 1))
I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.
I want to calculate last 4 any weekdays total sales.Based on filter max date.
Example: I have 2 filter
1. Date range(From -To)
2. Week Day(Like Mon,Tue Etc.)
I need total sales for last 4 Monday or Tuesday (as per above filter ).And Last 4 weekdays will be calculated based on To-date in filter.
Like To-date is 31-Dec'18 then last 4 Tuesday will be 4,11,18,25 Dec.
Thanks in advance for the help.
Nitika, the best way to do that is creating another table to put a 'Dimension' with dates, int that you can put, weekday, day, holiday, year, month...
Something like that:
Do You Need a Date Dimension?
Why use a Date Dimension Table in a Data Warehouse
Doing that you can reference your atual date with this table, and get just the weekday that you are looking for
I have rows of data based on dates and employee details.
For eg, I have date column, employee ID and Prokect ID. The data is from january 1st to january 22nd.
I want to compare each dates data and see if there is any change in the employees ID for the next date.
If i have 200 employees on january 1 and 203 employees on january 2, I need to show the difference as 3 in the new column.
How can i do the row comparison and do this calculation?