I have two tables, table1 & table2. I created 'Union' of these two tables in PowerBI.
table1
id city fruit table
a1 NY apple table1
a2 NY apple table1
a3 NY pear table1
a4 MI pear table1
a5 MI apple table1
a6 MI strawberry table1
a7 TO strawberry table1
a8 TO strawberry table1
a9 TO kiwi table1
table2
id city fruit table
a11 NY rockmelon table2
a12 NY rockmelon table2
a13 BJ pear table2
a14 BJ pear table2
a15 BJ apple table2
a16 LA blueberry table2
a17 LA blueberry table2
a18 PA blueberry table2
a19 PA kiwi table2
I would like to create a filter "filter1", which takes all rows if fulfilling these criteria:
"city" in table1 is "MI", or "fruit" in table2 is "blueberry".
If the criteria is met, call it "Awesome" in the dropdown of "filter1".
Can you please see if the following measure is in the right direction, and how to proceed? Thank you.
filter1 =
VAR
table1 = FILTER('Union', 'Union'[table]="table1" && 'Union'[city]="MI")
VAR
table2 = FILTER('Union', 'Union'[table]="table2" && 'Union'[fruit]="blueberry")
Awesome_test =
var filter1 =
FILTER(union, union[city]= "MI" && union[table]="table1")
var filter2 =
FILTER(union, union[fruit]= "blueberry" && union[table]="table2")
var filter3 = UNION(filter1, filter2)
RETURN
CALCULATE(MAX(union[id]), filter3)
// then pull the new measure into filter, select all that contains "a", then only those that fulfill the requirements are retained.
Related
I have two tables A and B as shown below. The AccountID in A has a relationship with the AccountID in B.
A
AccountID CmpName AccFlag SysStartTime
A1 Test1 1 1/1/2020
A2 Test2 0 1/2/2020
A3 Test3 1 1/2/2020
B
ContactId AccountID ConFlag SysStartTime
C1 A1 1 1/1/2020
C2 A1 1 1/1/2020
C3 A1 0 1/1/2020
C4 A2 1 1/2/2020
I want to get the count of records in A that have 3 related records in B. I did this using a calculated column with the DAX:
getcount = COUNTROWS(RELATEDTABLE(B))
And then created another calculated column to flag the one's with getcount = 3.
But the problem is that I want to check the count of records in A that have 3 related records in B at a given time. So I need to filter by the sysStartTime's in both the tables. For example, I want to get the count of records in A that have 3 related records in B as of 1/1/2010. So the result should be 1. Please advise on how I can do this using a Measure instead of a calculated column.
You should be able to do something like this:
SUMX ( A, IF ( COUNTROWS ( RELATEDTABLE ( B ) ) = 3, 1 ) )
Assuming you have a date table with a relationship to both A and B, a slicer on that date table will apply to the measure and you can set whatever dates you want.
I have a table1 that contains 4 different kind of ids
Data table1;
Input id1 $ id2 $ id3 $ final_id $;
Datalines;
1 a a1 p
2 b b2 q
- c c2 r
3 d - s
4 - d4 t
A table2 contains any of the ids from id1, id2 or id3 of table1:
Data table1;
Input id $ col1 $ col2 $;
Datalines;
1 gsh ywu
b hsjs kall
c2 jsjs ywe
3 sja weei
d4 ase uwh
I want to left join table1 on table2 such that I get a new column in table2 giving me final_id from table1.
How do i go about this problem?
Please help.
Thank you.
You can do it using SQL:
proc SQL noprint;
create table merged as
select b.final_id, a.*
from table2 as a left join table1 as b
on (a.id eq b.id1 or a.id eq b.id2 or a.id eq b.id3)
;
quit;
I have 2 tables connected to each other through col A. I want to match the column C with Col A and get the value of Col B.
For Example,
Table 1
ColA ColB Colc
a a1 b
a b1 c
c c1 a
Table2
ColA ColB
a a1
b b1
c c1
Now, I have already created relationships between Table2 and Table1 for my other calculations connecting both the tables with the colA.
Now, I am trying to match ColC from Table1 with ColA of Table2 and return the value of ColB from Table2 as MatchedOutput.
Expected output
Table1
ColA ColB Colc MatchedOutput
a a1 b b1
a b1 c c1
c c1 a a1
The DAX function for this is LOOKUPVALUE.
MatchedOutput = LOOKUPVALUE(Table2[ColB],Table2[ColA],Table1[ColC])
This looks for the value in Table2[ColB] where Table2[ColA] matches Table1[ColC].
I want to match the value in Column1 of one table with another and get the maximum value of column2.
For Example I have two tables,
Table 1
Col1 Col2
AA 17
AA 20
AB 10
AB 21
Table 2
Col1 Col2
AA ?
AB ?
I want my output to look like this,
Col1 Col2
AA 20
AB 21
I have tried,
Col2 = Max(Table1[col2])
but it didn't help. Thanks. Please share your thoughts.
You can use the following DAX:
Col2 =
CALCULATE(
MAX(Table1[Col2]),
FILTER(
Table1,
Table1[Col1] = Table2[Col1]
)
)
Result:
I have two model classes: Class A which represents table_a and Class B which represents table_b. Is there a way to aggregate or annotate Class A to include the value of a field in Class B other than the column that is aggregated on?
The SQL query that would accomplish what I need is as follows:
SELECT
a.*,
b2.col2
FROM table_a AS a
LEFT JOIN (SELECT
max(col1) AS m,
a_id
FROM table_b
GROUP BY a_id) AS b1 ON b1.a_id = a.id
LEFT JOIN table_b AS b2 ON b1.a_id = b2.a_id AND b2.col1 = b1.m
But the aggregate function only returns the data that would be retrieved with this:
SELECT
a.*,
b1.m
FROM table_a AS a
LEFT JOIN (SELECT
max(col1) AS m,
a_id
FROM table_b
GROUP BY a_id) AS b1 ON b1.a_id = a.id