Power BI - struggling with a Sum with specific condidions - powerbi

I need to calculate the biggest vendor by the sum of net sales.
Here is a example of my dataset:
Vendor
Net Sales
Vendor A
100
Vendor B
100
Vendor A
50
As you can see, the Vendor A (150) sold more then the vendor B (100).
So i need to calculate a measure that gives me the sum of the net sales of the biggest vendor, in this case that would be vendor A.
How can i calculate this ?
Example of what i want to see in the card:
150 $ - Vendor A

You can get what you want to see in the card using that measure.
MaxVendor =
VAR T1 = SUMMARIZE(SalesTable, SalesTable[Vendor], "Net Sales", SUM(SalesTable[Net Sales]))
VAR MaxSales = MAXX(T1, [Net Sales])
VAR MaxRecord = FILTER(T1, [Net Sales] = MaxSales)
RETURN
MAXX(MaxRecord, [Net Sales]) & " $ - " & MAXX(MaxRecord, [Vendor])

Related

Sum of a column but give the average of the sum for every applied filter?

I give here a sample data:
As you see we have a fact table for monthly expenses, and daily occupancy FT with row for every day for each residence. The residents vary but most of them are permanent. I think this is not
The goal is to find the expense for each resident per day.
The calculation for that is:
PRPD expense = SUM ( actual_amount) / SUM ( number_of_residents )
I put that PRPD expense in a card on the report page and I have filters for Year, Month and Residence Name.
If I select both residences for January the calculation is as follows:
(3000+2500) / (30+31+31) = **59.78**
In reality we have:
For Residence A:
3000 / (30+31) = 49.18
For Residence B:
2500 / 31 = 80.65
The average for both residences:
(49.18 + 80.65) = **64.92**
And the average is what we need. How do I accomplish this?
Thank you in advance.

Distribute yearly measure over months with predefired percent values

I have a yearly goal for number of graduates. I want to distribute this yearly number to monthly level using predefined percent numbers.
I would like to get
jan = 1.7% * 292 = 4.96
feb = 1.4% * 292 = 4.01
etc...
The problem is that yearly number of graduates has date of 2021-01-01 and relation to date table, so it will only work for the first month. (Other months are blank). I cannot change the date relation because I have other goals in the same table that use month
Here are my measures
Graduates goal = CALCULATE( SUM(value), Measure = 'Graduates goal')
Goal% = CALCULATE( SUM(value), Measure = 'Graduates%)
Montly graduate target = CALCULATE( [Graduates goal] * [Goal%])
I have tried using ALL(Dates[Month]) ALL(Dates[Year]) but I cannot get past that month level restriction in yearly goal.
Update:
I was able to solve this with crossfilter something like this
Montly graduate target = CALCULATE([Graduates goal], CROSSFILTER( Goals, Dates, None), YEAR(Pvm) = YEAR(TODAY())) * Goal%

Power Bi - Lookup for A Value in Different Table (Reference Table) and Return True

In Microsoft Power Bi
I have 850 products and a total of 15 vendors for these products.
I have two tables where the 1st table shows distinct list of products with only 8 vendors sorted from lowest to highest price (1 to 8):
and the second table shows the actual buying of every product with vendor name, quantity and price:
I need a column that checks if the vendor exists among the 8 choices for each product and return true. If not, it should return false.
Hope it's clear.
Thanks all :)
You can use this below Measure for your purpose-
true_false =
var current_row_product = MIN(Table2[product])
var current_row_vendor = MIN(Table2[vendor])
var find_vendor =
CALCULATE(
MAX(Table1[product]),
FILTER(
ALL(Table1),
Table1[product] = current_row_product
&& current_row_vendor IN
{
Table1[1st],
Table1[2nd],
Table1[3rd],
Table1[4th],
Table1[5th],
Table1[6th],
Table1[7th],
Table1[8th]
}
)
)
RETURN IF(find_vendor = BLANK(), "FALSE", "TRUE")
Here below is the output-

Count of products where sum of sales for particular product is higher than 2% of total sales - Power BI - DAX Measure

I have facts tables with sales
I would like to create measure that counts number of products where sum of sales for particular product is higher than 2% of total sales.
For example:
1. sum of sales for 'ProductKey' 310 is 5000.
2. sum of sales for 'ProductKey' 346 is 2000.
3. 2% of sum of total sales is 3000.
Product 310 would be included in count product 346 wouldn't be included in count.
How would I write such measure?
I've tried to created something like this:
Big Sales =
var SalesTotal = CALCULATE(SUM(fact_InternetSales[SalesAmount]))
var twoperceSalesAmount =
CALCULATE (SUM(fact_InternetSales[SalesAmount]), ALL( fact_InternetSales )) * 0.02
return
CALCULATE (COUNT(fact_InternetSales[ProductKey]),
FILTER (fact_InternetSales, SalesTotal - twoperceSalesAmount > 0))
Thansk
Kind regards,
Robert
You were almost there.
The pseudoalgorithm is:
1. Calculate threshold
2. Consider only product with sales above threshold
3. Count number of products
Big Sales:=
var _threshold = CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02
var _productlist =
FILTER(ADDCOLUMNS(
SUMMARIZE(
fact_InternetSales,
fact_InternetSales[ProductKey),
"productsales",CALCULATE(SUM(fact_InternetSales[SalesAmount]))),
[productsales]>_threshold)
RETURN
Countrows(_productlist)
If it is very slow web can optimize it.
Also solution with SUMX works:
Big Sales SUMX =
SUMX(VALUES(fact_InternetSales[ProductKey]),
IF(CALCULATE(SUM(fact_InternetSales[SalesAmount]))>
CALCULATE(SUM(fact_InternetSales[SalesAmount]),ALL(fact_InternetSales))*0.02,1))

Power BI DAX calculated column to find alternatives from a different table

I have the following datasets:
"Compare Data" table:
"Full Data" table
I'm looking to create a calculated column where I can later show and count who and how many alternative vendors to A and their Average Costs if "Model" and "Group" columns are used as slicers.
Ex:
If W5 is chosen from the "Model" slicer AND/OR EEC is selected from the "Group" slicer,
• Alternatives to A = B & E & R [Ignore A in the results]
• Number of Alternatives = 3
• Average Cost:
A = (100 + 150 + 105 +3000 +1215)/5 = 914
B = 85/1 = 85
E = 1115/1 = 1115
R = 450/1 = 450
I don't know if it should be a calculated column or a measure because I'd like to put these information in a Bubble Chart later where it shows A's Average Cost and its alternatives' costs with regard to "Model" and "Group" slicers.
Please if you have any solutions, can you show me how to get this done? Thank you so much!