Forum Discussion
manojk_pbi
6 months agoHelper V
Need help in writing DAX for calculated Column/Measure
Hello Friends,
I have two tables like below, I need to compare the data in master table with transaction table to check all entries available, if anything missing report it.
Master Data
| PrjID | PrjName | Last Passed Gate |
| P1 | Prj1 | G5 |
| P2 | Prj2 | G4 |
| P3 | Prj3 | G5 |
| P4 | Prj4 | G5 |
Output table
| PrjID | PrjName | Last Passed Gate | Missing Gate |
| P1 | Prj1 | G5 | G4 |
| P2 | Prj2 | G4 | G2 |
| P3 | Prj3 | G5 | All |
| P4 | Prj4 | G5 |
TransactionTable
| PrjID | Gate | Gate Date |
| P1 | G0 | 02-Feb-2024 |
| P1 | G2 | 02-Jun-2024 |
| P1 | G5 | 02-Dec-2024 |
| P2 | G0 | 02-Feb-2024 |
| P2 | G4 | 02-Dec-2024 |
| P4 | G0 | 02-Feb-2005 |
| P4 | G2 | 02-Jun-2024 |
| P4 | G4 | 02-Feb-2005 |
| P4 | G5 | 02-Feb-2006 |
Hi manojk_pbi
Frist Create one table using below dax
Gate Order =
DATATABLE(
"Gate", STRING,
"GateSeq", INTEGER,
{
{"G0", 0},
{"G2", 2},
{"G4", 4},
{"G5", 5}
}
)
Can you please try the below DAX measures ?Missing Gate =VAR CurrentPrj = SELECTEDVALUE('Master Data'[PrjID])VAR LastGate =LOOKUPVALUE('Gate Order'[GateSeq],'Gate Order'[Gate],SELECTEDVALUE('Master Data'[Last Passed Gate]))
VAR ExpectedGates =FILTER(ALL('Gate Order'),'Gate Order'[GateSeq] < LastGate)
VAR ActualGates =CALCULATETABLE(VALUES(TransactionTable[Gate]),TransactionTable[PrjID] = CurrentPrj)
VAR Missing =EXCEPT(SELECTCOLUMNS(ExpectedGates, "Gate", 'Gate Order'[Gate]),ActualGates)
RETURNIF(COUNTROWS(Missing) = 0,"All",CONCATENATEX(Missing, [Gate], ", "))
Result
If this answers you questions, kindly accept it as a solution and give kudos.
2 Replies
- mdaatifraza5556Super User
Hi manojk_pbi
Frist Create one table using below dax
Gate Order =
DATATABLE(
"Gate", STRING,
"GateSeq", INTEGER,
{
{"G0", 0},
{"G2", 2},
{"G4", 4},
{"G5", 5}
}
)
Can you please try the below DAX measures ?Missing Gate =VAR CurrentPrj = SELECTEDVALUE('Master Data'[PrjID])VAR LastGate =LOOKUPVALUE('Gate Order'[GateSeq],'Gate Order'[Gate],SELECTEDVALUE('Master Data'[Last Passed Gate]))
VAR ExpectedGates =FILTER(ALL('Gate Order'),'Gate Order'[GateSeq] < LastGate)
VAR ActualGates =CALCULATETABLE(VALUES(TransactionTable[Gate]),TransactionTable[PrjID] = CurrentPrj)
VAR Missing =EXCEPT(SELECTCOLUMNS(ExpectedGates, "Gate", 'Gate Order'[Gate]),ActualGates)
RETURNIF(COUNTROWS(Missing) = 0,"All",CONCATENATEX(Missing, [Gate], ", "))
Result
If this answers you questions, kindly accept it as a solution and give kudos.- manojk_pbiHelper V
Thanks for your quick reply. Let me try the sample provided by you.