Tried a lot but didn't get any expected result.
I need a DAX measure which shows me the second result:
Based on my 2 tables, I need to know how many products is active if they appear in the second table - then 1, else 0
Product1
A
B
C
D
E
F
Product2
A
J
K
A
B
J
F
F
F
The result should be:
Product Measure
A 1
B 1
C 0
D 0
E 0
F 1
Count: 3
Try the following:
In the data model view, make a relationship between Product1 table and Product2 table... this should load by default as a one to many relationship
Make a new table in Power BI or a pivot table in Excel. Put Products column from Products1 table on rows
Write a new measure as follows and drop it into your table
Measure Name =
IF(
COUNTROWS(Product2) > 0, 1, 0
)
Hopefully something like that works for you.
Jake
Related
Ive got this update query that uses employee activity stored in two tables (Beldata_filter & Urenlog_filter) to create a performance analysis per employee in another table (Bellers_filter).
however, i cannot get my query to update the performance stats per employee using only the activities of that employee in the other two tables, instead, access updates the stats per employee to the total activities of all employees.
here is the update query that i have written, the '.Beller' and '.Naam' signify columns in the tables with the names of the employees that i would like access to distinguish from one another.
UPDATE (Bellers_Filter INNER JOIN Urenlog_Filter ON Bellers_Filter.Naam=[Urenlog_Filter].Naam) INNER JOIN Beldata_Filter ON Bellers_Filter.[Naam]=[Beldata_Filter].Beller SET
Bellers_Filter.[Num b] = Dcount("[Beller]","[Beldata_Filter]"),
Bellers_Filter.[Num o] = Dcount("[Opgenomen]","[Beldata_Filter]","Opgenomen = 1"), Bellers_Filter.[Num nno] = Dcount("[Actie]","[Beldata_Filter]","Actie = 3"),
WHERE ([Beldata_Filter].Beller=[Urenlog_Filter].Naam);
The source table Beldata_filter looks like this:
Beller
ID
Moment
Opgenomen
Actie
Robert
55
8-11-2022
1
1
Susan
56
8-11-2022
1
1
Robert
55
9-11-2022
1
2
Robert
55
9-11-2022
0
3
Susan
56
9-11-2022
1
1
in this table each observation describes an action conducted by an employee. The other source table Urenlog_filter has got the same format, in this case the significance of the data in the tables is not as important as the observations of the data.
The table that will be updated needs to look like this
Id
Naam
Num b
Num o
Num nno
1
Robert
3
2
1
2
Susan
2
2
0
This is the desired result in its most simple form, the update query recognises 3 observations for robert and 2 for Susan under "Num b". Right now, the table looks like this
Id
Naam
Num b
Num o
Num nno
1
Robert
5
4
1
2
Susan
5
4
1
Who can help me with this problem? If you guys need more info please let me know!
Saving aggregate data is usually unnecessary and bad design. If it can be calculated for UPDATE, it can be calculated when needed.
SELECT Beldata_Filter.ID, Beldata_Filter.Beller,
Count(Beldata_Filter.Moment) AS [Num n],
Count(IIf([Opgenomen]=1,[Opgenomen],Null)) AS [Num o],
Count(IIf([Actie]=3,[Actie],Null)) AS [Num nno]
FROM Beldata_Filter
GROUP BY Beldata_Filter.ID, Beldata_Filter.Beller;
However, if you really must save, I don't see need for JOINing tables.
Include filter criteria in DCount() for names.
UPDATE Bellers_Filter SET
[Num b] = DCount("*","Beldata_Filter","Beller='" & [Naam] & "'"),
[Num o] = DCount("*","Beldata_Filter","Beller='" & [Naam] & "' AND Opgenomen=1"),
[Num nno] = Dcount("*","[Beldata_Filter]","Beller='" & [Naam] & "' AND Actie = 3");
I have a data frame containing two columns - ID and SHOP, and I want to find the count of unique Customer IDs that correspond to unique combination of shops in the Shop column. My original data frame is as follows
CustomerID
SHOP
1
A
2
A
3
B
1
C
2
D
4
E
The intended output should be as follows:
SHOP PAIR
CUSTOMERS
A-C
1
A-D
1
Is there a smart way to achieve this in R? Thanks for the help!
hi i have two query result:
Table A
Id u
1 50,00
2 60,00
3 70,00
and
Table B
id c
4 110,00
5 120,01
6 130,02
Now i have doing two query on this table and i want sum their query result.
I want update column c from table B with 160 that is sum of(110+50).
Table B
Id c
4 160,00
Table B and Table A they have nothing in common.
Now i have doing two query for select their value ed for sum two data:
$data=number_format($row['c']+$row1['u']);
$query_updatee="update B set c= (integer)$data where c=110,00";
Can i sum the data from two different table that don't have nothing in comon?
My output is pg_query(): Query failed: ERRORE: syntax error at or near "1" LINE 1: update B set punti = (integer)1680,00 where c=110,00 ^ in C:\xampp\htdocs\table_A.php on line 81
You can use a subquery to fetch the increment. The rest seems to just be filtering:
update B
set c = c + (select a.u from a where a.id = 1)
where B.id = 4;
Obviously, you can use where b.c = 110.00 if you want to filter by a number (or use a comma if that is how the database is set up).
I have a simple task which I cannot wrap my head around being a novice coder.
I have a data set which I am trying to manipulate.
It appears as this:
UniqueID Day Var AverageVar
1 1 X
1 2 Y
1 3 Z
2 1 A
2 2 B
2 3 C
I would like to create this new "AverageVar" variable which computes an average across the three days for each unique ID.
So, for example, the AverageVar for the first three rows I would like to create and have (X + Y + Z)/3 displayed. Is there any easy code for this in SQL or R?
SELECT * INTO newtable
FROM
(SELECT UniqueID, AVG(Var) as AverageVar
FROM table
GROUP BY UniqueID);
SELECT O.UniqueID, O.Day, O.Var, N.AverageVar
FROM oldtable O
INNER JOIN
newtable N
ON O.UniqueID = N.UniqueID;
I'm using Presto. If I have a table like:
ID CATEGORY VALUE
1 a ...
1 b
1 c
2 a
2 b
3 b
3 d
3 e
3 f
How would you convert to the below without writing a case statement for each combination?
ID A B C D E F
1
2
3
I've never used Presto and the documentation seems pretty thin, but based on this article it looks like you could do
SELECT
id,
kv['A'] AS A,
kv['B'] AS B,
kv['C'] AS C,
kv['D'] AS D,
kv['E'] AS E,
kv['F'] AS F
FROM (
SELECT id, map_agg(category, value) kv
FROM vtable
GROUP BY id
) t
Although I'd recommend doing this in the display layer if possible since you have to specify the columns. Most reporting tools and UI grids support some sort of dynamic pivoting that will create columns based on the source data.
My 2 cents:
If you know "possible" values:
SELECT
m['web'] AS web,
m['shopping'] AS shopping,
m['news'] AS news,
m['music'] AS music,
m['images'] AS images,
m['videos'] AS videos,
m[''] AS empty
FROM (
SELECT histogram(data_tab) AS m
FROM datahub
WHERE
year = 2017
AND month = 5
AND day = 7
AND name = 'search'
) searches
No PIVOT function (yet)!