DAX porblem with a sum - powerbi

I'm trying to calculate a simple sum of sales for different products but i have a visualization problem.
I have 2 different tables:
"Master data" where i can find all the informations about a porduct (product ID, description etc)
"total sales" where i can find for each product_ID the total sales amount
These tables are connected by a relationship based on the "product_ID".
I have created a table with product_ID (from "Master data") and total sales (from "total sales") but it returns the same amount of sales for every product ID (the sum of sales of all products)
Exemple:
product_ID_1 100€
product_ID_2 100€
product_ID_3 200€
I visualize the incorrect values like this:
product_ID_1 400€
product_ID_2 400€
product_ID_3 400€
Thanks in advance!!!
Ersilia

This is absolutely impossible!
If you put 'Master Data'[Product ID] next to [Sum Total Sales] in one table visual, then 'Master Data'[Product ID] will filter [Sum Total Sales].
If you see the Total of [Sum Total Sales] in every row, then YOU ARE NOT FILTERING, because you clearly don't have a relationship between 'Master Data' and 'Total Sales'. Check that in the Model view: The line is either missing, or dotted (inactive).
But with the given sample data from above you should have a one-to-one relationship between the Product ID's, although in general this will be a one-to-many relationship, since every product is probably sold more than once.
I'd recommend using more general sample data to check this out and not to use the same names for tables and their columns and esp. not 'Total' everywhere, so that you don't end up with such confusing expressions like "Total of [Sum Total Sales]". This is asking for trouble.

Related

How do I manipulate measure values based on 2 other dimension tables

Power BI newbie here and I'm trying to figure how to craft my DAX to manipulate my measure values based on certain criteria in the other two tables.
Currently I have 2 separate tables which are joined by a One to Many relationship and a separate Measures table. (Total Sales Price is computed as sum of Sales Price)
My aim is to create a new measure where Total Sales Price is multiplied by 1.5x when DIM_Product_Type[Product Category] = "High".
New Measure =
CALCULATE (
SUM ( FACT_PriceDetails[Sales Price] ),
FILTER ( DIM_Product_Type, DIM_Product_Type[Product Category] = "High" )
) * 1.5
However this returns no values in my visual and I'm trying to discern if its a matter of the table joins or the DAX expressions.
Thank you for your time!
Your measure seems good.
It will select only those products with a Product Category of "High" and multiply them by 1.5 to give you result. i.e. Give me the sum of all "High" Product category Price details multiplied by 1.5.
What you need to check is:
Product Serial Numbers match across the two tables
Your Product Category does indeed contain the category "High"
You have entries in FACT_PriceDetails that link to a DIM_Product_Type that has a category of "High"
Check you have not set any filters that could be hijacking your results (e.g. excluding the "High" product category product type or the realated fact/s)
Option-1
You can do some Transformation in Power Query Editor to create a new column new sales price with applying conditions as stated below-
First, Merge you Dim and Fact table and bring the Product Category value to your Fact table as below-
You have Product Category value in each row after expanding the Table after merge. Now create a custom column as shown below-
Finally, you can go to your report and create your Total Sales measure using the new column new sales price
Option-2
You can also archive the same using DAX as stated below-
First, create a Custom Column as below-
sales amount new =
if(
RELATED(dim_product_type[product category]) = "High",
fact_pricedetails[sales price] * 1.5,
fact_pricedetails[sales price]
)
Now create your Total Sales Amount measure as below-
total_sales_amount = SUM(fact_pricedetails[sales amount new])
For both above case, you will get the same output.

DAX TopN Behavior

Just wanted to confirm my understanding (or lack thereof) around these two formulas - in an orders table where each row is an order:
TOPN(10,ALL(Orders),[Total Sales]) - looks at the individual Sales amount for each row and returns the whole table with just the top 10 records sorted by the Sales field; using the measure Total Sales(defined as Sum of Sales) in this context doesn't really have an effect as the aggregation is at a single row level which just keeps it the same.
TOPN(10,ALL(Orders[Customer Name]),[Total Sales]) - this actually groups by the customer name, calculates the total sales, and returns the top 10 customer names based on that metric; it's more or less equivalent to this SQL:
select customer_name, sum(sales) as Total_Sales from orders
group by customer_name
order by Total_Sales desc
limit 10

Create Custom Column with IF and lookup functionality to own table

I have merged two tabels ( sales and forecast ). For all the rows coming from sales query the cost price column has a value. The forecast rows does not have that.
In order to calculate future metrics/KPI I need to make a Power Query transformation that populates cost price on all forecast rows. I would like to do some kind of refence to the ProductName (exits both on the sales and forecast rows) and pull the cost price from the sales rows. The ProductName can have multiple entries in the table, but will be the same for alle the rows. So maybe a find first/max or something would be fine.
However, I am not sure have to make this calcuated column with some sort of lookup to ProductName?
Well you can definitely do so
Here is an excellent Article form Microsoft on LookupValue
In addition check this Thread as well. It will give you more Idea.
I would do something like
=LOOKUPVALUE(Product[SafetyStockLevel], [ProductName], " Mountain-400-W Silver, 46")

DAX Calculate Sum of sales per productid filter by productid ( NOT IN TOP 20 )

I am fairly new to PowerBI DAX and I want to filter out the top 20 product ids in a measure.
I came up with this formula but it does not seem to be working and I was hoping to get some help here.
$ Amount Parcel =
CALCULATE(
SUM(Data[$ Amount Parcel]),
FILTER (Data, NOT (Data[idProduct], SUM(Data[NetSales])) IN TOPN(20, SUMMARIZE(Data, Data[idProduct], "NetSales", SUM(Data[NetSales]))))
)
I want to show sales per PID for all products except for our 20 best sellers.
Thank you !!
I would suggest an easier approach adding a dimension column.
First of all, you need to have Product dimension table separated from Sales fact table. Make sure to create one-to-many relationship between Product and Sales with "Single" cross filter direction.
Then you can create a calculated column on Product table, which can be used to filter out top selling products.
Sales Rank = RANKX('Product', CALCULATE(SUM(Sales[SalesAmount])))
Now drag and drop Sales Rank field into the Filters pane of your visualization, and set the filter condition so that top selling products will not be shown.

Create calculated measure from other table with filters

I have four tables which I have tried related and unrelated:
Store (column "Store Number")
Calendar (column "Sales Date")
SKU (column "SKU Code")
Sales (columns "Store Number", "Sales Date",
"SKU Code" and "Sales Quantity")
I have slicers on the Calendar and SKU tables
I need to list all stores with total "Sales Quantity" for each store and at the same time to limit the sales quantity to the two slicers mentioned above. Basically, I need to list these columns:
Store Number - from the Store table (no filtering from Slicers)
Store Name - from the Store table (no filtering from Slicers)
Total Quantity of Sales for the Store - calculated measure filtered by Calendar and SKU slicers
So my question is, what DAX required to create the calculated measure?
Please note I must list ALL stores regardless of whether they have sales in the stipulated period.
I've tried various DAX functions such as TREATAS, SUMMARIZE, ETC.
I've tried with and without active relationships and with no relationships.
The closest I've got is the code below, but it excludes stores with zero sales. I need all stores regardless of their sales.
Qty by Store = CALCULATE(
sum(Sales[Sales Qty])
,USERELATIONSHIP(
Sales[Store Number]
,Store[Store Number]
)
)
The problem with the output I've managed is that stores without sales are excluded from the list. I need to have them included.
Keep the relationship active, and change the DAX formula to
Qty by Store =
VAR res = sum(Sales[Sales Quantity])
RETURN IF (ISBLANK(res), 0, res)
There is no need for USERELATIONSHIP(). Relationship Store - Sales is already active. The reason why the number of stores changes in the table visual is because when there is no sale for a particular store Qty by store measure returns BLANK and those BLANKs get filtered out by the table.
Result:
An easy way to make a blank return zero instead is to simply append +0 to your measure formula.
Qty by Store = SUM ( Sales[Sates Quantity] ) + 0
This works because DAX calculates BLANK() + 0 = 0.