Forum Discussion
Dax - comparing rows in one table based on multiple parameters.
- 1 year ago
So I found a solution.
I dont't know if its the best- but it works.
I created a bunch of new columns using the LOOKUPVALUE commend.
The columns I created per situationexample for the comparisons :
1- rows where the tables are different and the unit and contract is the same.
I brought the date from the rows with Table=prod in cases where the unit and contract matchDateIn2Table= LOOKUPVALUE('Table'[Date], 'Table'[Id], 'Table'[Id], 'Table'[Unit], 'Table'[unit], 'Table'[Contract], 'Table'[Contract], 'Table'[Table] = "prod")and then I just added a column comparing dates between Table=test and Table= prod
outcome comparison 1= IF('table'[Table]= "prod", "",
IF('Table'[Date]='table'[DateIn2Table], "", "Different Date"
))2- rows where the table and contract is the same
I first created an index for the different units per Id and table.
I needed to create a new column that combined the Id and tableIdTable = 'Table'[Id] & 'Table'[Table]
and then the index
Index2 = RANK(DENSE, ORDERBY('Table'[Unit],ASC),PARTITIONBY('Table'[IdTable]))
Then I got the dates in cases where the Id, Contract ant table match and the index is 1 higher
2date = LOOKUPVALUE('Table'[Date], 'Table'[Id], 'Table'[Id], 'Table'[Contract], 'Table'[Contract], 'Table'[Table], 'Table'[Table], 'Table'[Index2], 'Table'[Index2]-1)
and then I compered the two dates
outcome comparison 2= IF('Table'[Date]='table'[2Date] , "", "Different Date")3- rows where the table and unit are the same and the date is the next one (the most complicated one)
I created another index based on Id, unit, table and start date.
First i created a new Id combining Id, unit, table.IdUnitTable = 'Table'[Id] & 'Table'[Unit] & 'Table'[Table]
then the index
Index = RANK(DENSE, ORDERBY('Table'[Date],ASC),PARTITIONBY('Table'[IdUnitTable]))
then I got the contract from each earlier date
Pre_Contract = LOOKUPVALUE('Table'[Contract], 'Table'[Id], 'Table'[Id], 'Table'[Unit], 'Table'[Unit], 'Table'[Table], 'Table'[Table], 'Table'[Index], 'Table'[Index]-1)
and last I compered the two contracts
outcome comparison 3 = IF('Table'[Index]=1, "",
IF('Table'[Contract]-'Table'[Pre_Contract]=11, "", "Contracts in wrong order"
))The explanation is kinda messy, but I hope it will help someone in the future.
Hi Sharkybu
I use Table as a placeholder for the name of your table.
1. Navigate to this palce and add a new column
2.
MEASURE =
IF (
Table[Table] <> Table[Contract]
&& Table[Unit] = Table[Contract],
1,
IF ( Table[Table] = Table[Contract], 2, BLANK () )
)
This should give you a 1 in the first example and a 2 in the secound example, I am not sure I understand what you want in the third example can you say a bit more about it?
But I hope this can get you going.
I see that I didnt make sense, so I edited the post.