DAX compare to previous row and update upstream rows per condition - powerbi

I am struggling in solving the following requirement on table attached.
I need to create a “Cross location” column where the result of the column looks on previous row and compares if the value on the location column matches.
If it does than the output is “No” but if it doesn’t it outputs “Yes” to all upstream rows of the Group which is indexed by the task number column.
** This is as small portion of the table which consists many groups and multiple task numbers which not always starts with 1 put per group is always consecutive.
Appreciate your support - table of interest attached in picture
enter image description here
Group task number location Cross location
A 1 CAT
A 2 CAT No
A 3 TGR Yes
A 4 TGR Yes
A 5 JGR Yes
A 6 CAT Yes
B 19 JGR
B 20 CAT Yes
B 21 CAT Yes
B 22 TGR Yes

Related

How to create a dimension table in PowerBI

I have 2 data source, each has its own dimensions and fact table.
Both data sources have a dimension called "Country"
Dimension 1 for Data Source 1
Country | Country Order
Australia | 1
Singapore | 2
Indonesia | 3
..
Dimension 2 for Data Source 2
Country | Country Order
AUSTRALIA | 1
SINGAPORE | 2
INDONESIA | 3
..
Data Source 1 Dimension Table 1 has more countries compared to Data Source 2 Dimension Table 2.
I am building a dashboard and i want to use country as a common filter, meaning one filter that can filter 2 different fact table.
I have tried creating a new table that contain one column with all the distinct values and tried to create relationship to both dimension table but it keep promoting me an error - circular dependency.
Any other methods that can work for this?
Thanks!
I find it best to create my dimension tables in PQ. Create a new query named country_dimension that is an append of your two fact tables. Remove all other columns and then remove duplicates. You can then use this in your model and you won't get any circular dependency problems.

Informatica : Count the number of rows based on sequence of number

I have table where source has 1 column, like below. for example, column name is A and I have set of records in the source.
A
1
1
1
2
2
3
I want to populate two columns in target, Say columns are A and B.
Column A in the Target has same values as in source and column B has count
A B
1 1
1 2
1 3
2 1
2 2
3 1
Can someone please explain how can i achieve this.
Thanks in advance
If source is a dbms like oracle, you can use source qualifier overwrite sql like below. Use row number and partition by to generate sequence for every A.
Select
A, row_number() over(partition by A order by A) as B
From mytable
If you're looking for infomatica only solution then this is how you can do it.
Sort the data by column A
Use ex transformation, create one in/out two var, and one out port.
We are going to compare first val with prev val, if they r same, add 1to the sequence else start from 1 again.
A in/out
v_B = iif (A=prev_A, v_B +1, 1)
prev_A=A
o_B =v_B
Link A and o_B to the target.

Changing organization of data so that each observation represents a new variable (I tried)

I am working in Stata with a dataset on electric vehicle charging stations. Variables include
station_name name of charging station
review_text all of the customer reviews for a specific station delimited by }{
num_reviews number of customer reviews.
I'm trying to make a new file where each observation represents one customer review in a new variable customer_review and another variable station_id has the name of the corresponding station. So, if the original dataset had 100 observations (one per station) with 5 reviews each, the new file should have 500 observations.
How can I do this? I would include some code I have tried but I have no idea how to start.
If your data look like this:
station reviews n
1. 1 {good}{bad}{great} 3
2. 2 {poor}{excellent} 2
Then the following:
split(reviews), parse(}{)
drop reviews n
reshape long reviews, i(station) j(review_num)
drop if reviews==""
replace reviews = subinstr(reviews, "}","",.)
replace reviews = subinstr(reviews, "{","",.)
will produce:
station review~m reviews
1. 1 1 good
2. 1 2 bad
3. 1 3 great
4. 2 1 poor
5. 2 2 excellent

Display Related Value in Table Visual With a Hierarchy

Data
Main
Group
Subgroup
Value
Composite Key
A
1
1
A - 1
A
2
2
A - 2
B
1
3
B - 1
C
1
4
C - 1
C
1
5
C - 1
C
2
6
C - 2
C
2
7
C - 2
Targets
Group
Subgroup
Target
Composite Key
A
1
10
A - 1
A
2
11
A - 2
B
1
12
B - 1
C
1
13
C - 1
C
2
14
C - 2
Setup
I have 2 datasets like the ones given above. Table main stores, well, my main data and table targets defines tragets for each combination of Group and Subgroup. I want to bring this 2 tables in a relation. Thus, I created columns in each table which paste the 2 key columns (Group and Subgroup together (Composite Key) and defined an 1:n relationship between these 2 tables.
Furthermore, I defined a hierarchy on Group > Subgroup on the main table (lets call it group hierarchy).
Goal
I want to show a matrix visual which uses group hierarchy in the rows (effectively allowing to fold / unfold the groups), some measure as values. So far so good. Now I want to add the target from table targets to the visual and here is where I am struggling, because if I simply add Targets[Target] to the visual it only shows the overall average of the targets and not the average of the specific group. Hence, I guess I need to define a meausre myself which does some RELATEDTABLE magic to pull the correct target, but I am totally at loss of how to do that. Any ideas?
It turned out that I need to define the hierarchy on Targets as well and use this hierarchy in the visual:
Then the numbers were calculated properly:

SQLite C++ Compare two tables within the same database for matching records

I want to be able to compare two tables within the same SQLite Database using a C++ interface for matching records. Here are my two tables
Table name : temptrigrams
ID TEMPTRIGRAM
---------- ----------
1 The cat ran
2 Compare two tables
3 Alex went home
4 Mark sat down
5 this database blows
6 data with a
7 table disco ninja
++78
Table Name: spamtrigrams
ID TRIGRAM
---------- ----------
1 Sam's nice ham
2 Tuesday was cold
3 Alex stood up
4 Mark passed out
5 this database is
6 date with a
7 disco stew pot
++10000
The first table has two columns and 85 records and the second table has two columns with 10007 records.
I would like to take the first table and compare the records within the TEMPTRIGRAM column and compare it against the TRIGRAM columun in the second table and return the number of matches across the tables. So if (ID:1 'The Cat Ran' appears in 'spamtrigrams', I would like that counted and returned with the total at the end as an integer.
Could somebody please explain the syntax for the query to perform this action?
Thank you.
This is a join query with an aggregation. My guess is that you want the number of matches per trigram:
select t1.temptrigram, count(t2.trigram)
from table1 t1 left outer join
table2 t2
on t1.temptrigram = t2.trigram
group by t1.temptrigram;
If you just want the number of matches:
select count(t2.trigram)
from table1 t1 join
table2 t2
on t1.temptrigram = t2.trigram;