March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi All,
I am getting stuck in converting a SQL query to DAX.
I want distinct count of ColumnA when all IDs in columnB has value = 'NK'(ColumnC). This needs to be checked for every Date(grouped by date). So from the below example, for 11/8/2024, the DAX needs to return the total of 1(Because only 145 has all column B values with NK and the others have a mix of K and NK). For 11/1/2024, the total will be 0. Basically counting Column A when all the grouped values in Column B have NK
This DAX is used in a matrix which splits these counts based on aging bucket and area.
Greatly appreciate the help.
The SQL that wrote is as below (wrote based on checking the negative condition)
select distinct ColumnA from TableA
(
(select count(1) from TableA TA1 where TA.ColumnA = TA1.ColumnA and TA.Date=TA1.Date and (TA1.ColumnB='K' or TA1.columnA is null)
)=0
)
Table A
Date | ColumnA | ColumnB | ColumnC |
11/8/2024 | 123 | 345 | K |
11/8/2024 | 123 | 333 | |
11/8/2024 | 145 | 678 | NK |
11/8/2024 | 145 | 666 | NK |
11/8/2024 | 145 | 786 | NK |
11/8/2024 | 157 | 567 | NK |
11/8/2024 | 157 | 555 | K |
11/1/2024 | 145 | 666 | K |
11/1/2024 | 145 | 786 | NK |
Solved! Go to Solution.
hi @Msri ,
try like:
measure =
VAR _table =
ADDCOLUMNS(
SUMMARIZE(
data,
data[date],
data[ColumnA]
),
"ColC",
CALCULATE(
CONCATENATEX(
VALUES(data[ColumnC]),
data[ColumnC], ", "
)
)
)
VAR _result =
COUNTROWS(
FILTER(
_table,
[ColC]="NK"
)
)
RETURN _result
hi @Msri ,
try like:
measure =
VAR _table =
ADDCOLUMNS(
SUMMARIZE(
data,
data[date],
data[ColumnA]
),
"ColC",
CALCULATE(
CONCATENATEX(
VALUES(data[ColumnC]),
data[ColumnC], ", "
)
)
)
VAR _result =
COUNTROWS(
FILTER(
_table,
[ColC]="NK"
)
)
RETURN _result
Thanks for the reply. I added the above measure, but I am getting 0 as total. From SQL I got 9 rows
@Msri This works?
Measure 2 =
INT (
COUNTROWS ( Msri ) =
CALCULATE (
COUNTROWS ( VALUES ( Msri[ColumnB] ) ),
Msri[ColumnC] = "NK"
)
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
18 | |
16 | |
13 |