I have a two tables are Data and Report.
Data Table:
In Data table contain two columns are item and supplier code. The item column contain text & number and supplier code column contain as a text.
Summary if CHE record in DATA:
if any of the items have CHE records in the data table, get the values if only one CHE record, and if there is more than one CHE record then compare each column (length and Supplier) and if any of the columns has different value then return MIXED otherwise return Actual value
Summary if no CHE record
if only one none CHE record in the data table then returns the actual values but if more than one none CHE records in the data table for that time, compare the values of each column, and if any column value is different then return MIXED otherwise value.
Summary: no record found in DATA table:
Return N/A
Logic
My first priority is “CHE” and second priority is “KKR” in order get the length and supplier from Data table into the Report Table.
Scenario 1;
If two different supplier {“CHE” & “KKR”} for the same item in data table then I would like to get the data (length and supplier) against “CHE” in report table according to the item. (Please refer the item 123 and 5678 in both tables ”Data” and “Report”)
Scenario 2;
If supplier not repeated according to the item and the item contain either any of these supplier {“CHE” or “KKR”} in data table, in these scenario pull the data (length and supplier) against the item in report table based on the availability in data table. (Please refer the item 5555, 6666, 9876 and 2345 in both tables ”Data” and “Report”)
Scenario 3;
If supplier not repeated according to the item and the item contain either any of these supplier {“CHE” or “KKR”} but the length & supplier are different in data table in these scenario return as a text “Mixed” were belongs to (column; either length or supplier or both) in report table according to the item. (Please refer the item 123456 and 567 in both tables ”Data” and “Report”)
Scenario 4;
If two different supplier {“CHE” & “KKR”} for the same item in data table but the length and supplier are variable in data table in this scenario return as a text “Mixed” were belongs to (column; either length or supplier or both) in report table according to the item. (Please refer the item 116 in both tables ”Data” and “Report”)
Scenario 5;
If records not found in date table the return as “NA” in report table according to the item. (Please refer the items in report in table 4444, 12 and 10)
I am looking for calculated column option in order to achieve my result.
Current logic
I created New table for order for supplier priority
I created two helper column for running count and unique count
Finally I am applying the following calculated column in report table
LENGTH = LOOKUPVALUE(
DATA[Length],
DATA[ITEM],REPORT[ITEM],
DATA[UNIQUE_COUNT],1,"NA")
it almost working fine but it will give a wrong result (item 123456 and 567) were my desired is "Mixed" in report table. I highlighted in red and green snapshot for your reference.
My final result look like this
Herewith attached the PowerBi file for your reference https://www.dropbox.com/s/p81uy12tfh1htwu/AUOM1.pbix?dl=0
Can you please advise.
It's not entirely clear what you're trying to do but I think this measure pattern may help you:
IF (
DISTINCTCOUNT ( DATA[SUPPLIER] ) > 1,
"MIXED",
SELECTEDVALUE ( DATA[SUPPLIER], "NA" )
)
For more than one value, you get MIXED. For one value, you get that single value. For no values, you get NA.
Related
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.
I have a table like shown below titled Employees:
Name LOC1 LOC2 LOC3 LOC4
-----------------------------------------
Joe DAY CVG DTW
Jane PVD STL
John LAX SAN SFO ANC
I created a measure to combine the LOC fields into 1 result separated by a space. I keep getting errors because PBi wants to aggregate the data fields. All fields are type Text. I've tried all the usual combine methods, below are a couple of examples...
CombineLOCs=CONCATENATE('Employees'[LOC1],'Employees'[LOC2])
CombineLOCs= 'Employees'[LOC1] & " " & 'Employees"[LOC2]
This is what I get back:
"A single value for column 'LOC1' in table 'Employees' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation....etc."
I ultimately have a table visual on my canvas and instead of listing out all of the columns on that table, I just want 1 column with all of the combined LOC values for each employee in it.
If you just want a single column where the LOC columns are joined together, then you need to create a new column within the table, rather than a new measure. A measure expects you to aggregate the values. A column will concatenate the text strings on a row by row basis.
If you select the new column option, either on the table tools or the fields sidebar, then use the concatenate formula in your question, that should work.
With the new column, you can then include the employee name and the associated LOC values.
Please find my expected result below
But I am getting result as below
where I have choosed Order Id from orders table and Product Id from Order Items tables and I have used below measure
order_to_orderitem = CALCULATE(SUM('Order Items'[Unit Price]),USERELATIONSHIP(orders[key12],'Order Items'[key12]))
Note: key12 is merged column of Order Id and Product Id in both orders and Order Items table
I have a datamodel as shown below
I have given a relationship as shown below
It has been created as shown below where From Table is Order Items and To Table is orders whereas while creating I have given orders as From Table and Order Items as To Table
Orders table:
Order Items table:
If you want to return all rows from the orders table and the matching rows from the Order Items table you can just create a new table with LEFT JOIN.
NewTable = NATURALLEFTOUTERJOIN ('orders', 'Order Items' )
(the function works for the tables that don't have the same column names). To get this table check "Show items with no data" for the first column.
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
I'm trying to make a line and stacked column chart like this:
The problem is that the values of my database doesn't match with the line
values.
My chart have 2 levels in the hierarchy, one of Departments and another of
Subdepartments. The line value is the objetive of each subdepartment and
columns are the quatity of occupational accident by each subdepartment.
Considering this I have 3 tables:
OPS, this table contains the quantity of occupational accident
DEPARTMENTS, this table contains subdepartments and departments
OBJETIVES, this table contains the objetive by subdepartment (This table was created by myself in Excel)
This is my Departments table where ID is the subdepartmentID(as "Nombre" in my table) and DepartamentoPadreID is the Department that have another subdepartments. E.G.
The ID 113 that is Petronor contains another departments as 114= Economico Financiera, 115= Fiabilidad y Mantenimiento and so on that's why departments 114 and 115 are subdepartments inside Petronor (113) and the subdepartment Economico Financiera(114) what is subdepartments from Petronor contains another departments.
This is the relationship beetween my tables:
My Departments table is joined with OPS by the ID and it has many relations with OPS because we distinguish beetween
IDDepartment
ID from observed department
ID from observer department
The table below contains the objetive by each of subdepartment:
And this is my chart by subdepartments:
As you can see i didn't put any blank or null value in my table and my chart is taking blanks values.
Someone know what's the error? It's weird because i did the same with another 3 tables and i don't have any error.