Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Simple setup:
I need a measure that calculates number of dimension keys that have no facts at all - e.g. either no rows in the fact table, or only rows with null values in the fact table.
Filters in DAX CALCULATE, unfortunately, only allow filtering based on column values, while here we need filting based on per-dimension aggregate.
EDIT: there seems to be no easy solution for such trivial task. Sad.
Hi @DmitryKo ,
If I understand correctly, you would like to get the count of dimension keys which have no facts at all(1. no rows in fact table; 2. the value of key is null in the fact table). If yes, you can create a measure as below to get it:
measures =
VAR _tab =
CALCULATETABLE (
VALUES ( 'facttable'[key] ),
FILTER ( 'facttable', 'facttable'[value] = BLANK () )
)
RETURN
CALCULATE (
DISTINCTCOUNT ( 'dimensiontable'[key] ),
FILTER (
'dimensiontable',
'dimensiontable'[key]
IN _tab
|| NOT ( 'dimensiontable'[key] IN VALUES ( 'facttable'[key] ) )
)
)
If the above one can't help you get the expected result, please provide some raw data in your fact table and dimension table (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Sample data set as small as this:
Keys
Alpha |
Beta |
Omega |
Facts
Key | Value |
Alpha | (null) |
Beta | (null) |
Beta | 1 |
Result set:
Key | Measure result |
Alpha | 1 |
Beta | 0 |
Omega | 1 |
Hi @DmitryKo ,
You can create a measure as below to get it, please find the details in the attachment.
Measure =
VAR _selkey =
SELECTEDVALUE ( 'Keys'[Key] )
VAR _tab1 =
CALCULATETABLE (
VALUES ( 'Keys'[Key] ),
FILTER ( 'Keys', NOT ( 'Keys'[key] IN VALUES ( 'Facts'[key] ) ) )
)
VAR _count =
CALCULATE (
DISTINCTCOUNT ( Facts[Value] ),
FILTER ( 'Facts', 'Facts'[Key] = _selkey )
)
VAR _countnull =
CALCULATE (
DISTINCTCOUNT ( Facts[Value] ),
FILTER ( 'Facts', 'Facts'[Key] = _selkey && 'Facts'[Value] = BLANK () )
)
RETURN
IF ( _selkey IN _tab1 || _count = _countnull, 1, 0 )
Best Regards
This would only work (correctly or not) when only one key is selected, due to this:
VAR _selkey = SELECTEDVALUE ( 'Keys'[Key] )
so it's useless in any real scenario that might include more than one key and/or aggregations over many other dimensions
EDIT: it produces incorrect results over sample dataset anyways
Hi @DmitryKo ,
How did you set the visuals in your report? Could you please share a simplified pbix file with me? You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
This code returns wrong result (false positives) and seems wrong anyways.
For example, "_tab" variable there would contain all keys that HAVE AT LEAST ONE row with nulls in the fact table, while we need to return keys that HAVE ONLY rows with nulls in the fact table. This is the part that causes false positives.
If we exclude it from the filter expression, we have empty result table over sample dataset, e.g. this part is wrong as well:
NOT ( 'dimensiontable'[key] IN VALUES ( 'facttable'[key] ) )
If specific fact is never present (as a row) in the fact table for a given key, wouldn't VALUES(facttable[key]) result in a empty list as well, rendering "IN" expression useless?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
15 | |
11 | |
8 | |
8 | |
8 |
User | Count |
---|---|
22 | |
13 | |
11 | |
10 | |
10 |