How to display top 3 highest amount info for a record from a table? - powerbi

For one of the tables imported into the PowerBI, I have columns as Company Name, Debit Amount, Credit Amount and Net Amount (Calculated column: Debit Amount- Credit Amount).
Now is it possible to pull the three highest Company Names from the table in terms of having either higher Debit, Credit or Net Amount and display it on a tile? May be by creating a measure using DAX or OOTB? It should look like:
Top Grossing Second Grossing Third Grossing
12000(Net Amount) 10000(Net Amount) 5000 (Net Amount)
Company Name Company Name Company Name
I am envisioning the above in terms of tiles and they would change dynamically once anything updates in the data source table. Not sure if this is possible to do using DAX, I am open to suggestions. Any help will be greatly appreciated. Thanks.

DAX has a TOPN() function that you can use for this sort of thing.
The other possibility is to use the built-in advanced filtering. Under the visual level filters, choose filter type Top N, pick how many you want to show and what value you are sorting by.

Related

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/

Power BI: Filter based on SUM

I have a horizontal bar visual where I’ve plotted the users with the highest sales.
It is "user name" vs "SUM(sales)" (user names and sales are in two different tables).
I’ve also used a filter as I only want to see users with SUM(sales)>1000€.
Now, on this page I want to put other visuals so that I can see information about this group of users, such as:
How many users are there?
What's the average age?
How many men and women?
and so on...
However, if I use a page level filter on sales, I can only filter a single sale value and not the sum for the user.
How can I filter the page based on a user’s total sales?
You could create a calculated column for a user’s total sales in your username table and then filter based on that.
Total Sales = CALCULATE(SUM(Table2[sales]))
There’re also solutions utilizing GROUP BY if you prefer that.

Getting measure to only show positive values in matrix Power BI

I'm new to DAX. Looking for your expertise. Looked all over the web but couldn't find a proper solution.
I have a matrix that shows several factories and it's inventories, the rows being factory and SKU. I've created a measure that's the difference between two other measures. The overall idea is: I have a inventory quantity and an orders volume. I defined a "balance" measure that's inventory - sales. That is, what is still left for sale.
Normally it works fine, but when I have a negative value in balance, things get messed up. The subtotal in the factory row sums all the numbers, including negatives, giving me a balance subtotal that is smaller than it's supposed to be. I can't count the negatives. So I've tried to solve this by defining the measure as
Balance = IF([Inventory]>[Sales],[Inventory] - [Sales],BLANK())
Now this works fine visually to display only the positive values in balance, but still sums up the negatives in the factory subtotal.
How can I make this measure to only show and sum up the positives?
I appreciate your help.
P.S.: the inventory and sales measures are basically SUM's of different tables for simplicity and understanding by my part
Matrix with measures. The columns are "Estoque" as inventory, "Embarque programado total" as sales and "Saldo Disp. Venda" as the balance
Create a measure with the below code.
Balance = CALCULATE(SUM([Inventory]) - SUM([Sales]), FILTER(Table1, [Inventory]>[Sales]))
As it turns out, I was able to find a solution through trial and error. I changed my measure to (FatoEstoque is the table that contains the inventory numbers):
Balance= CALCULATE([Inventory]-[Sales],FILTER(FatoEstoque,[Inventory]>[Sales]))
Although I'm not even sure why it works (lol), it works! So I'm not complaining. This measure only sums up the positive values, showing the correct subtotal as I needed.
Filtering the Inventory table to values where [Inventory]>[Sales] works, but adding another filter with the Sales table and the same condition don't.
Here is an image comparing the results. The new measure is called SaldVender2

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.