Building DAX Gateway Analysis formula - powerbi

I need to build a formula in DAX that will show the number of customers who purchased again after their initial purchase, broken out by Product. I have a standard data warehouse with a Order Placed fact table, a Customer dimension table, and a Product dimension table. I am able to find the number of customers who purchased each product on their initial purchase by using this formula:
First Purchase Customer Count = CALCULATE(DISTINCTCOUNT(Demand[CustomerKey]),Demand[Customer Order Sequence Number] = 1)
My visual is a table with the Product as the only attribute, so this first formula is being calculated per Product. The next formula needs to count the number of customers who bought a second time, regardless of what Product they purchased that second time, but it should only include customers who purchased the current Product the first time. I have successfully created this formula to do it, but it usually errors out on the 1M row limit unless I filter the Product by subcategory.
Rebuyer Count = COUNTROWS(INTERSECT(SUMMARIZE(FILTER(Demand,Demand[Customer Order Sequence Number] = 1),[CustomerKey]),SUMMARIZE(CALCULATETABLE(FILTER(Demand,Demand[Customer Order Sequence Number] = 2),all('Product')),[CustomerKey])))
How can I improve this formula so it will run without bombing?

Old question, but on the off-chance that this is still an issue for you, have you reviewed the New and Returning Customers pattern on DaxPatterns.com? http://www.daxpatterns.com/new-and-returning-customers/
Your returning customers solution is creating a table of first-time customers, and then a table of second-time customers, and then joining those two tables together to count the number of first-time customers who are also a second-time customer.
The DaxPatterns solution is slightly different. Rather than calculating 2 potentially large tables of customers on the fly and then joining them, it is counting existing customers who have made a prior purchase.
You would need to adapt their solution to meet your requirements. They have a concept of Absolute Returning Customers (meaning the customer's first-purchase was for any product, and their second purchase was for the specific product you care about). You want the reverse of that (the customer's first-purchase was for a specific product, and their second purchase can be anything).
Overall, however, you'll have less bombing out if you start from a single list of first-time customers and filter out the customers you don't want (i.e. who never bought again) vs. compiling 2 separate lists of customers and intersecting them.
(It's the difference between letting everyone into the theatre, then throwing out everyone without a ticket, vs. checking tickets at the door and only letting people with a ticket in).

Related

Power BI Relationship established, but # values are the same when leveraging

I have created a relationship between multiple data sources and am trying to leverage information across them. I ideally want to show the cost associated with different banking transactions by company. These would come from the deals table and the cost table - the two at either end of the relationship.
I tried deleting blanks, removing excess values etc. I am hoping the relationship can be fixed.
ENTITY_INFO filters PAYMENTS but not Cost.
To calculate the total cost of all payments for a company, add a measure like
TotalPaymentCost = sumx(PAYMENTS,RELATED(Cost[Cost]))
. Most commonly this measure would be added to the PAYMENTS table, but it doesn't actually matter what table you put measures on.

Calculate difference between two dates in different tables not directly related in PowerBI

I need to calculate the time elapsed between to dates, in days. The values are the creation date and the payment date for every invoice in my model table. I will use this value to classify my invoices: sort by time passed, classyfy them, make a Pareto Chart... etc. So I need to create a calculated column in the inoice model table (can't imagine an approach using measures).
But I have two handicaps:
Tables ARE NOT DIRECTLY RELATED, so I can't use the RELATED function
The invoice can be paid in several installments
So, for each invoice, I need to calculate de time elapsed, in days, between the generation date (in a table) and the MAX payment date of all it's installments (in another indirectly related table)
This:
DaysElapsedInPayment = DATEDIFF(Invoices[InvoiceDate], Max(RELATED(Installments[InstallmentPaymentDate])), DAY)
would work if the tables were directly related an DateDiff whould accept MAX, but no, it's not the case. For your information, if could be usefull to you, this is my invoice-payment model scheme:
Could you help me, please?
EDIT:
As requested, I explain more deeply my data model...
My model looks complex because an invoice can be paid by several payments (part in cash, part in direct debit, for example), so a invoice can have MULTIPLE payments. At the same time, a payment can involve several invoices. Thats why my invoices-payments is many-to-many. And also, a payment (for example a payment by direct debit) can be divided in installments that are monthly sent to bank.
My model has lots of tables, not in english. For my purpose, I mock the needed ones here:
As you can see in the mocked data:
One invoice is paid in a single payment. It's the common case. We only have a single payment date in 'Payments'. That one is the one I need.
Another invoice is paid in TWO payments (part in cash, part payed by VISA), in different days. I need the date of the LAST of both payments.
Last case, I have two invoices that will be paid as a 'SINGLE' payment. Both should have to return the PaymentDate in Payments. But, at the las moment, we agreed with the client to pay them in installments. So installments are created, each one with a DueDate an the date wuere they were finally payed. So I need to get the LAST date of all installments for this payment.
It's complex, I know, but at the end, is about:
Given a value, find related values in anoter table indirectly related
From all values found, get the greatest
The function must perform theese operations, and put the results in a calculated column.
Have you triend creating a Calendar Table with the AUTOCALENDAR function? That way you could create a relation between both tables to make the calculations. Let me know if you need further assistance in order to add this table to the model

Power BI: Categorize customers based on measures

I have a list of customers that I wish to categorize based on two criteria: Share of total income and average time from due date to payment date.
I have a table with customer transactions that I can use to calculate these two criteria.
The solution I currently have is to use calculated columns in the customer table:
Sum of invoiced amount per customer/Total sum all customers = Share of total income
Average number of days per customer
I then use IF-functions to categorize these metrics into Big/Medium/Small customers, and Good/Medium/Bad payers.
Next I use a Matrix visualization to see number of customers for each category (Big customer/Good payer, Small Customer/Medium payer, and so on).
The problem I get is that the outcome of this is static, and they doesn't change if I use slicers to get only transactions from one year, or for only one of our companies.
Can I instead use measures for this, and get a dynamic Matrix visualization?
You need to use measures for this. It is a common pattern known as dynamic segmentation. You can read how to implement it here: https://www.daxpatterns.com/dynamic-segmentation/

Count occurrences in time

Working with unemployment data, and I want to count the number of weeks that a client has received benefits during the last 52 weeks.
I have a dataset with many tables which are all connected via the client number in a fact table. In the fact table the client number occurs for every week of the year in one column, another column shows the type of benefits (if any) received in the current week. So I have a long format.
The other two relevant tables contains
A: List of client number appearing only once per client, but no information about benefits received or week number.
B: List of benefits
Tried counting the rows in my fact table while filtering so as only to do so for the specific benefit I am interested in, but I can't make it work so far.
Weeks on benefit A =
CALCULATE(DISTINCTCOUNT(FactDream[DimDreamBorger]);
DimDreamYdelse[dagpenge] = 1)
sample data
I just need a table showing how many weeks the individual client has received a specific benefit, but I keep getting a total sum of the weeks that all the clients have received the benefit.
Best would be if you add the following measure:
=CountRows(YourTable)
Put this measure into a chart visual. Then add a filter visual and put your Benefit column into the filter visual.
This way you can filter after your benefits, which you are interested, and see the result in the chart.

Saved search report in Netsuite

I want to create a report in Netsuite ERP that shows me the information about Departments Sales and Budget by Month. I think I can achieve this by creating a saved search that chooses this items, however I don't understand under which category I can find this fields. A saved search would be ideal as I am trying to authomatize the reports in a java application, and I discovered that I can call the savedSearch results.
I found the Department under the standard Criteria in the subcategory "Owner..." and I added a Date standard criteria with the values "within this month", however I have not found the group that contains all the Sales/Income/Margin or the budget (though, I found an aggregation sum function that may be used along with a field). I will appreciate any help. Also, will the addition of this fileds be enough to get the Sales X Department X Date information or do I have to use a different join method?
Thanks!
You'd have to combine two saved searches to achieve this.One on budgets for the period you need. The department column is available on the budgets saved search.
The other would be transactions for the period. Generally budgets are against posting transactions so Invoices, Cash Sales, Credit Memos and Cash Refunds would be in your other search. If you group those by Department you could then combine the two searches in code to create your own budget vs actuals report.