DAX formula to get total number of sales in a Calculated Column at a lookup table - filter

I have received answers to my last question. Thanks to all. Now I have another query. I have a lookup table, called Products and a transaction table, called Sales. The relationship between them is one to many. I want to make a Calculated Column at Product to get the total number of sales for each product. I tried to apply Calculate function as solution.
Product [total number of sales] =
Countrows ( Filter (Product, Calculate (Sum( Sales [SalesAmount])))).
I expected products in each row in Product table shall filter the sum of sales amount and generate a virtual table with all the entries related to a particular product. And finally, Countrows shall count the number of entries. But on the contrary, it resulted with same number in each row.
I am just a beginner in DAX. I tried to solve it depending on context transition concept. But my guess was wrong. Please help me out. Thank you in advance.

Use RELATEDTABLE:
If you just want the number of entries in the Sales table per product:
=
COUNTROWS(
RELATEDTABLE( Sales )
)
If you want the total sales per product:
=
SUMX(
RELATEDTABLE( Sales ),
Sales[SalesAmount]
)

Related

how to VLOOKUP a measure result in DAX Power BI

i have Excel Dashboard like this
i want to replicate this in PBI but the result is not the same
in my PBI measure, the Total SKU is
Total SKU = CALCULATE( DISTINCTCOUNT(CSDPVSXML[ProductId]),
ALL('DT Active'), NOT( ISBLANK(CSDPVSXML[ProductId])))
Total SKU 2 = CALCULATE( DISTINCTCOUNT(CSDPVSXML[ProductId]), NOT( ISBLANK(CSDPVSXML[ProductId])))
Total SKU XML 2 using the same DAX script as Total SKU, is there a way to achieve the same result as the excel version, since i cant vlookup in PBI into DAX result, lookup function in PBI only lokup into predefined table, not the result of a measure
thank you in advanced
LookUP is working only with a table, not with a visual. Looking through your question, I assume that you just need to exclude distributor value from filtering.
Try this code:
Total SKU 2 =
CALCULATE(
[Total SKU]
,ALL(tblName[DISTRIBUTOR])
)
new measure
Total SKU 2 =
CALCULATE(
[Total SKU]
,CSDPVSXML[AreaOfPricing]=SELECTEDVALUE(Customer Hierarky[Format Level 3])
,ALL(tblName[DISTRIBUTOR])
)

TOPN DAX function not working. The formula is returning all the rows and not TOP 3

My goal is to create measure to get top 3 customer Names and there respective sales.
I am using the below measure to bring top 3 names along with there sales. The below measure is returning all the rows. I fail to understand why this is happening and why filtering is not happening for top 3 customers
topN = calculate(sum(Sale[Total Excluding Tax]),
TOPN(3,
values(Sale[Employee Name]),
calculate(sum(Sale[Total Excluding Tax]))
)
)
Sale[Employee Name] is calculated column and is coming from another table Employee by using Employee Name = RELATED(Employee[Employee])
The DAX is working properly and grabbing top 3 records. Order/sorting is important. You need to order your results.
Create a calculate column [Total Excluding Tax] to sum up the Total excluding tax. Then use that column in a measure; try something like:
Top Sales = TOPN ( 3, ALLSELECTED( 'Sale' ), [Total Excluding Tax]), desc)

Laravel Eloquest join with max adn min value

Im trying to build a query that pulls the information from one table and also pulls the max and min value of that product in another table but cannot seem to get this to work.
This is what I have:
$rentals = Rentals::select('rentals.main_image','rentals.rental_name','rentals.slug','rentals.summary',DB::raw('max(prices.price) as price_high'),DB::raw('min(prices.price) as price_low'))
->leftjoin('prices', 'rentals.id', '=', 'prices.rental_id')
->where('destination',$destination_id)->paginate(6);
This returns 1 row ( there should be 88 ) and it gets me the highest and lowest price in the table regardless of rental_id. There are other factors that will filter into this like dates but for now I just need the rental info plus the highest and lowest price for that rental.

How can i solve this query in sql oracle?

It's an exercise that is not solved in the book in which I am studying.
The goal is to find the seller who has had the highest number of sales per month,
during all the months for which there is registered information. The problem is that I do not know how to divide tuples into periods of one month.
First table is:
Table Sellers
Id_seller
Name_Product
And the other one is:
Table Product
Name_Product
View_datetime
Budget
What did i do?
I made this query:
SELECT id_seller FROM(SELECT id_seller, COUNT(id_seller)
FROM SELLERS INNER JOIN PRODUCT
ON SELLERS.name_product = PRODUCT.name_product
GROUP BY id_seller HAVING COUNT(id_seller)>= 1
ORDER BY 2 DESC)
WHERE ROWNUM = 1;
The query returns me the seller that most sales has done, but not "per month since there are records" as the statement asks. Any ideas? I'm so lost...
The idea is to compare the total sales of each salesman in this month (sysdate), with those of a month ago, two months ago ... so long as there are older records. And get the maximum from each seller. And then you print the seller with more sales from the previous list. If a seller sells 400 products this month(April, the sysdate), but another seller sold in October last year 500, the result would be the second seller . That's what I do not know how to do.
Thanks ^^
You could try this query
select MonthName, id_seller, max(TotalSales) from (
select to_char(sysdate, 'Month') MonthName, sellers.id_seller, count(sellers.id_seller) TotalSales
from sellers inner join product
on sellers.name_product = product.name_product
group by to_char(view_datetime, 'Month'), sellers.id_seller
) tab
group by MonthName, id_seller
There are a few points to make...
The tables are weird. I assume your table sellers would better be called sales, right?
In this example, having count... >= 1 is a no-op. Count could only be 0 if there were no rows at all, in which case there would be no row in the group- by output. You can just leave this count away, here.
To get the sales per month, just add the month to the group by. I.e. group by id_seller, To_date(view_datetime,'YYYYMM').

how to I define measurement filter from other table in tabular

I am trying to make measure that gets sum of amt column where versiontype column = ative how do I write dax formula for that measure?
So let's say your fact table is called Sales. It has a Sales Amount called Amt. The table is linked to a Version table with a VersionType field that includes a value of "Active".
You could create a new measure for Active Sales as follows:
ActiveSales :=
CALCULATE (
SUM ( Sales[Amt] ),
'Version'[VersionType] = "Active"
)

Resources