Data distribution not showing in power bi though the models have relationship - powerbi

I have two models: Data and Product Master.
Their relationship is defined as joining by Category Name:
I have written measure as:
2. Total sales = SUM(Data[Sales Amount])
It appears as:
Then I checked:
It shows:
Why is not the distribution of category name and Name and showing in table?
Then after If , I uncheck measure 2. Total sales then it will show:
Why is the distribution of of category name and Name not showing according to total sales?

Check your relationship. Are you sure that you connect the correct columns? Data Type is that same? Any white space on one side of the relationship? "Tshirt " instead of "Tshirt"

Related

Get the unique customers with the highest Item value in Table Visualization in Power BI

I am struglling to getting top 25 unique customers when filtering the table using Alert_Id. Basically, I have these columns in table which you can find below. The goal is to show top 25 unique customers based on highest value. The Item can be repeated but name has to be unique. I have tried so many different things but nothing seems to be working as expected because of Multiple customers have used multiple items and hence I am getting duplicate rows. The table has to be dymic because whenever user filters the table using Alert_id it should return those top unique customers that associated with Alert_id(Alert_id is a single selection). So whenever user select their Alert_id that table should display their data. I have tried below measure,
First I created calculated column to break the tie for price because many Item shares the same price:
max price = Table[PRICE] + RAND()
Then I created another column to get max price for the customer name:
MAX column for table = CALCULATE(MAX('Table'[max price]), ALLEXCEPT(Table, Table[CUSTOMER_NAME]))
Then I created calculated table using these columns:
SELECTCOLUMNS(
FILTER(Table, Table[max price]=Table[MAX column for table]), "Name" ,Table[CUSTOMER_NAME],"Item",Table[ITEM], "PRICE",Table[MAX column for table], "Alert_ID", Table[ID], "DATE", Table[REQ_DATE], "ITEM_COUNT", Table[PK])
But, this is giving me all unique customers with the MAX value and I am getting blank table when I filter with Alert_ID even thought it has data but the customers are not with the MAX value. Basically, It's not dynamically capturing max values for each customer_name when filter is applied. And, I if there are multiple rows with same customer name which can have same exact value then I would choose any random row without considering which ITEM it is. I just want top 25 unique customers for one Alert_ID.
Here is the sample data,
Here is expected output if I select Alert_ID = 123 from filter and it can be different when I select different Alert_ID.
FYI: I have tried topn with max price and even with RANKX but no luck. I always endedup having multiple customers.
Any help or lead will be highly appreciated!
I was able to figure out how to get unique values. Here is the solution that worked for me.
First, I created calculated column with my price column and RAND function to break the ties:
sum value = Table[PRICE] + RAND()
Then, I have created one measure that calculates the rank:
rank with table = RANKX(CALCULATETABLE(VALUES('Table'[ITEM]), ALLSELECTED('Table'[ITEM])),CALCULATE(SUM(Table[sum value])), ,DESC, Dense )
Then I applied the filter on NAME column to get top 25 based on sum value calculated column. Also, dragged my measure on filters pane and applied the filter where Rank with table = 1.
That's how I got unique names with highest valued ITEM.

Amazon Redshift multi-aggregate rollup

I have a REDSHIFT dataset which includes customer purchases as a SKU level.
I'm struggling to produce a view that includes multiple aggregates at a customer level. For example my table includes columns like: customer_id, order_id, product_id, product_category, product_division, sales, units
From this base I'd like a result which looks like
customer_id
total_sales (i.e. sum of all SKU sales)
total_units
total_orders
categories_purchased (i.e. a distinct count of categories the customer purchased)
divisions_purchased
primary_category_sales (i.e. category with the highest sales)
primary_division_sales
primary_category_mix (i.e. primary category sales / total sales)
primary_division_mix
While I can aggregate results for the whole dataset, I can't seem to crack how to incorporate sub-aggregates like finding the maximum category and its relative contribution to total sales. Any help you can offer is most appreciated!
I have tried nesting queries + using window functions but keep running into errors like aggregate function calls may not have nested aggregate or window functions.

Merging queries on product number AND on date

For a report on bakery product performance I am trying to match the purchase price with the selling price in order to get to a product margin. The purchase price sits in a separate table and so does the selling price. Both tables contain product numbers so I am able to merge the two queries in order to get both selling price and purchase price on one line in order to compute a product margin.
The difficulty however is the fact that the selling prices and purchase prices are very subjective to change. Each line in both tables has a date field that is changing often. Therefore I would like to merge the queries in such a way that the selling price of a given product is corresponding to the purchase price of the same product, but also make sure that the date of the selling price and purchase price align.
How would I go about and do this?
Tables would look like this:
DATE - SHOP - PRODUCTNR - QUANTITY SOLD - TOTAL SALES - SELLING PRICE PER PRODUCT
DATE - PRODUCTNR - PURCHASE PRICE PER PRODUCT
You need to add a new column consisting of the [PRODUCTNR] and [DATE] fields. You can use a simple concatenate operation to achieve this:
For Example:
Let's say you have such a table:
Then you need to create a new column called [CompositeKey] in the table:
CompositeKey =
[DATE] & "-" & [PRODUCTNR]
Resulting Table:
Note: I used (-) character to separate columns. You can use any others, like pipe(|), underscore(_) etc...
Now you need to do the same for your 2nd table, and create a relationship between your [CompositeKey] columns on both tables. Now It will adapt to changing dates, and you will know which is which... I hope It solves your problem.

How to filter data based on other table field in power bi

I have 3 Tables Company, Employee, Card as shown in the screenshot below; the tables have relations between them.
We can notice from the card table that not every company has a card, or multiple cards related to it,
Requirement
I want to create a donut-chart to show the number of companies based on if the company has at least one card or "NO" (no card).
Example here; 50% Hold a card and 40% NO.
companies: 1,5,6,7,10 (have cards)
companies: 2,3,4,8,9 (Don't)
My solution
I merged the card_ID column from the Card table to the Company table (left join with Card table as second),
then created a new column "Card_Holder" that indicates "YES" if the card_ID Column is not empty and "NO" if its empty.
but when I applied the changes, power bi found a duplicate ID in the Company Table which is true, because the above steps created more than one record for each company based on the card table.
My solution is not good and its not working, and probably I am thinking with excel.
What is the appropriate method to do that in power BI?
You can create a calculated column in Company that computes the number of rows in Cards that are related to that Company, and return Yes if there are more than 0 rows, and No otherwise :
HasCard =
IF(
COUNTROWS( RELATEDTABLE( Card ) ) > 0,
"Yes",
"No")
Then use it as the legend of a pie chart which value is the count of Company[Company_Id]:
Note : If you want to do it in PowerQuery, you can group Card by Company_ID before left join

How to switch data from two tables based on filter in Power Bi

I have two tables which have counts and sales based on dates and one of them also have customer ID. The counts are not same when we see by customer and summary. I also have customer filter on my dashboard. What I want to achieve is if no customer is selected the count should come from summary table otherwise it should come from customer if multiple or one is selected in the filter.
Customer Table
Summary Table
Any hints, I have tried lookupvalue function but I cant put date as search value from date table.
It's much easier to use Measures, instead of creating calculated tables to obtain those metrics. Also, summarized tables would not have the same filter context your are looking for.
Measure 1
Total Customers =
DISTINCTCOUNT('Customer Table'[CustomerID])
Measure 2
Total Sales =
SUM ( 'Customer Table'[Sales])