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

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.

Related

Group 10 columns of data to gain distinct count of rows Power BI

I'm trying to display all of the distinct values within this table (there are many other columns in this table) and show how many rows each distinct value shows in.
I have tried to use group by but this does not work. It needs to be filterable by country from another column but i can do that by page filter.
I am trying to show what the top 5 associations are in terms of appearance.
enter image description here
Put the 10 columns in a Table visual. Then create this measure and add it too. Then sort descending on Distinct.
Distinct = COUNTROWS('Your Table Name')
To see only the Top 5, go to the Filter pane, and pick the first column and set the Filter type to Top N, and then Top 5 by the Distinct measure.

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])

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 retrieve rows with max value within a group based on date filter

i have the following table with some sample data similar to what we have in our model:
there will be a date filter called "As Of Date" that will be selected by the user. I will need to create a new measure that filters the above table using these rules each time:
rows where reserve date <= the As Of Date selected by the user
rows that are in "Approved" status
for each combination of Claim Id, Damage Id, and Location Id, get the row with the latest sequence number
sum the reserve value column
so based on the sample data above, if the user select an As Of Date of 8-1-2020, the measure should sum the Reserve Value from the following rows that meet the criteria:
What I am trying to achieve is a measure that would return 900 as that is the sum of the reserve values for the rows that meet the criteria, as listed in the second table above.
Thanks
scott

How do I compute distinct count on a column based on a user selection?

I have table with millions of rows, and I need to count distinct a column, after eliminating records using a user selection , say a table or slicer..
I tried the function , values , distinct count .. none of them are working as expected .
unique opners = DISTINCTCOUNT( 'dw useraction_fact'[user_id])
I expect to get a distinct count of users acting to a project that I can select, but the distinct count is calculated for each project and it's summed up.