Forum Discussion
Finding unique and intersect values using DAX URGENTTT
- 2 years ago
Adjust the first measure djust the logic to focus exclusively on `col_id = 15`. We want to count unique `main_id` values where `kre_id = 84` for `col_id = 15`, ensuring these `main_id` values do not have any other `kre_id` values associated with them within `col_id = 15`.
Adjusted Measure 1: Unique `main_id` for `kre_id = 84` within `col_id = 15`
Unique Main ID for KreID 84 and ColID 15 =
VAR FilteredTable =
FILTER (
YourTable,
YourTable[col_id] = 15
)
VAR MainIDsWithKreID84 =
CALCULATETABLE (
VALUES (FilteredTable[main_id]),
FilteredTable[kre_id] = 84
)
VAR MainIDsWithSingleKreID =
FILTER (
MainIDsWithKreID84,
CALCULATE (
COUNTROWS (FilteredTable),
ALLEXCEPT (FilteredTable, FilteredTable[main_id])
) = 1
)
RETURN
COUNTROWS (MainIDsWithSingleKreID)
From your problem description alone, you need 2 measures. Please follow the guidelines on how to submut a problem in this forum: How to Get Your Question Answered Quickly - Microsoft Fabric Community
Measure 1: Unique `main_id` Count for `kre_id = 84` and `col_id = 15`
1. Filter the table to include only rows where `kre_id = 84` and `col_id = 15`.
2. Count the unique `main_id` that do not appear with any other `kre_id`.
Unique Main ID Count =
VAR UniqueMainIDs =
CALCULATETABLE (
VALUES (YourTable[main_id]),
YourTable[kre_id] = 84,
YourTable[col_id] = 15
)
VAR MainIDsWithSingleKreID =
FILTER (
UniqueMainIDs,
CALCULATE (
COUNTROWS (YourTable),
ALLEXCEPT (YourTable, YourTable[main_id])
) = 1
)
RETURN
COUNTROWS (MainIDsWithSingleKreID)
Measure 2: Intersection Count for `kre_id = 84` with Other `kre_id` Values
This measure will be a bit more complex. We need to count intersections of `main_id` for each `kre_id` pair with `kre_id = 84` when `col_id = 15`.
1. Create a table that lists all `main_id` values associated with `kre_id = 84` and `col_id = 15`.
2. For each `kre_id`, count how many `main_id` values intersect with those in step 1, excluding `kre_id = 84`.
Intersection Count =
VAR KreID84MainIDs =
CALCULATETABLE (
VALUES (YourTable[main_id]),
YourTable[kre_id] = 84,
YourTable[col_id] = 15
)
RETURN
SUMX (
VALUES (YourTable[kre_id]),
VAR CurrentKreID = YourTable[kre_id]
VAR IntersectionCount =
IF (
CurrentKreID <> 84,
COUNTROWS (
INTERSECT (
KreID84MainIDs,
CALCULATETABLE (
VALUES (YourTable[main_id]),
YourTable[kre_id] = CurrentKreID,
YourTable[col_id] = 15
)
)
),
BLANK()
)
RETURN
IntersectionCount
)
This measure will give you a table of counts for each `kre_id` intersecting with `kre_id = 84`. You might need to adjust these formulas based on your specific data structure and requirements. Remember to replace `YourTable` with your actual table name.