DAX - IF value exist in related table - powerbi

I have two tables:
POHeader
POLines
In the POHeader table the PurchID is a unique value for each line, and I have a one-to-many relationship with PurchID in POLines.
Each PurchID in POHeader has a Status, which can be "Open order", "Received" or "Invoiced".
The same goes for each line in POLines.
If all the lines with the same PurchID in POLines has status "Received", the PurchID in POHeader will also have status "Received".
But if one line in POLines still has status "Open order" the status in POHeader for this PurchID will still be "Open order".
What I want to do is to create a calculated column in POHeader that check if a PurchID has status "Open order" in POHeader, and one line with the same PurchID, but status "Received" or "Invoiced" in POLines, which should then return the value "Partially received".

Related

Column with mutiples status - automatic today's date when status is changed to "completed"

I have a Microsoft List with a column named "Status" which is a column type with multiples choices.
I want the user to have today's date when he chose a certain choice from the column "Status".
For instance, when the status is "completed", then the column "Date of completion" shall display automatically today's date.
What would be the formula, and should it be entered in the column "Date of completion" parameter > column validation in the field "formula" ?
Or do I need to use power automate ?
Thanks for your help,
I would use column formatting for this.. I would use Power Automate for this.
Create a flow like below.
Use the When an item is created or modified trigger action.
In the Settings add a trigger expression like below (again change it to use the internal column names).
That expression checks if the Status field value is Completed and if the Date of Completion field is still empty.
#and(equals(triggerOutputs()?['body/Status/Value'], 'Completed'), empty(triggerOutputs()?['body/Dateofcompletion']))
In the Update Item use UtcNow for the Date of Completion field
utcNow()

Not able to get top 1 in power BI?

Customer table
contains the column "Status","created_date","updated date"
ascs table
contains the column "service_station_name"
First I add new measure for "status count" by using following eqn:
Status Count = COUNT('cps customers'[status])
then a new column for "day duration" by using following eqn:
Day Duration2 = SWITCH('cps
customers'[status],"Closed",DATEDIFF('cps customers'[created_at],
[updated_at],DAY),"Unattended",DATEDIFF('cps
customers'[created_at],NOW(),DAY),"Assigned",DATEDIFF('cps
customers'[created_at],NOW(),DAY),"NotApplicable",DATEDIFF('cps
customers'[created_at],NOW(),DAY),"Open",DATEDIFF('cps
customers'[created_at],NOW(),DAY))
I need top service station name..
Conditions:
i. Consider only **closed status**
ii. Top count of **closed status count**
iii. Lowest **time duration**
Steps:
Select columns service_station_name,status,status count and day duration2
Filter the closed status from column "status".
Add TOPN filteration for "status count"
Now, I got three service_station_name where each have 5 closed status count.
And for getting the lowest "day duration2" I used ascending order
"
And for displaying the top 1 service_station_name, I chosen the CARD from
visualization and get First service_station_name.Bt I haven't got the
proper answer
Then I took last service_station_name . Here also i haven't got the
answer.
Based on the screenshot, I need "Om Sakthi Engineering" as answer.
How I get the answer? Can anybody help me!
You could actually add in another column "NewColumn", then the value would be the "Status Count" divided by "day Duration". The highest value will be the top one.
NewColumn = divide(Table1[Status Count],Table1[Day Duration])
Then you can use card visualization to pick the top one value.
Under filters, you should filter status as closed, filter the top 1 for this NewColumn.

I keep getting duplicate results

I'm new to SQL and I'm using Oracle Apex. I am trying to run the following query:
Select COMPANIES.COMP_NO as "Company Id", COMP_NAME as Company",
OPEN_START_DATE as "Start Date", OPEN_TITLE as "Opening Title",
QF_CODE as "Required Qualification"
From OPENINGS, COMPANIES
Where COMP_ADDRESS='Auckland'
AND OPEN_START_DATE Between '12/01/2016' AND '12/31/2016';
I know there should only be four returned results but I keep getting duplicates of the same entry. What am I doing wrong?? I believe it must be something to do with my table connections... Thanks
select
c.comp_no,
c.comp_name,
o.start_date,
o.open_title
from
companies c
join openings o on o.comp_no=c.comp_no
where
start_date between '2016-10-01' and '2016-10-07';
use join instead of selecting it in the from clause.

Adding Data to Table with Foreign Key

I am trying to add one row of data into a table (Employee) that has a Foreign Key (ob_Num). Job_Num is referenced in the Job table. However, when I go to add the row I get the below error:
Msg 547, Level 16, State 0, Line 1 The INSERT statement conflicted
with the FOREIGN KEY constraint "FK__Employee__Job_Nu__5D60DB10". The
conflict occurred in database "team04", table "dbo.Job", column
'Job_Num'. The statement has been terminated.
My code is:
Insert into Employee Values (001, 'Celie', 'Davis', 457-457-4511, 002,
'01-05-2012', null);
002 is the job_num

SQLite INSERT command return error "column number is not unique"

I have a text file with rows (lines). Each row is a record in database table. I read this file and fill database.
Tables creating command:
CREATE TABLE gosts(number TEXT PRIMARY KEY, userNumber TEXT, status TEXT, date TEXT, title TEXT, engTitle TEXT, description TEXT, mainCategory INTEGER, category INTEGER, subCategory INTEGER);
Inserting query:
INSERT INTO gosts VALUES ("30331.8-95", "ÃÎÑÒ 30331.8-95", "Äåéñòâóþùèé", "01.07.1996", "Ýëåêòðîóñòàíîâêè çäàíèé. ×àñòü 4. Òðåáîâàíèÿ ïî îáåñïå÷åíèþ áåçîïàñíîñòè. Îáùèå òðåáîâàíèÿ ïî ïðèìåíåíèþ ìåð çàùèòû äëÿ îáåñïå÷åíèÿ áåçîïàñíîñòè. Òðåáîâàíèÿ ïî ïðèìåíåíèþ ìåð çàùèòû îò ïîðàæåíèÿ ýëåêòðè÷åñêèì òîêîì", "Electrical installations of buildings. Part 4. Protection for safety. Applisation of protective measues for safety. Measures of protection against electric shock", "Íàñòîÿùèé ñòàíäàðò óñòàíàâëèâàåò îáùèå òðåáîâàíèÿ ïî ïðèìåíåíèþ ìåð çàùèòû äëÿ îáåñïå÷åíèÿ áåçîïàñíîñòè è òðåáîâàíèÿ ïî ïðèìåíåíèþ ìåð çàùèòû îò ïîðàæåíèÿ ýëåêòðè÷åñêèì òîêîì ïðè ýêñïëóàòàöèè ýëåêòðîóñòàíîâîê çäàíèé", 37, 333, 628);
Please ignore encoding problems. Source file has cp1251 encoding, but inserting sample is taken from console. I tried to use utf-8 but had the same problem.
SQLite using code above:
if(sqlite3_prepare_v2(database, query, -1, &statement, 0) == SQLITE_OK) {
...
}
Function calling doesn't return SQLITE_OK. And I gea error message by:
string error = sqlite3_errmsg(database);
if(error != "not an error") cout << query << " " << error << endl;
Strangely, some records are inserted without error and I can't find differences between good and bad records.
I can provide more information if needed.
I would bet that the difference between the good and bad rows were whether or not the value associated with the 'number' column was already in the table.
This is one of the reasons that table designs usually do not use TEXT valued columns for PRIMARY KEYs.
If it is possible to re-create your table, I would create an ID field responsible for being the PRIMARY KEY for your table. Further enable the IDENTITY property for auto increment of your primary key value.
This should prevent insertion failure due to having duplicate values in the 'number' column.
Now if values in 'number' column must be unique then you should add a UNIQUE constraint on that column.
NOTE: The UNIQUE will yield the same error you are currently receiving as it appears you are trying to add multiple rows with the same value for column'number'
Review the SQLite CREATE TABLE documentation for more details.