Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Self Join with filter using DAX (not in Power Query)

I'm trying to create a measure using DAX to count distinct values from a Dim table with filter.

Objective: Count Distinct Signee from Dim between valid dates of given current date. These counts will be against each DocKey in the fact table.

 

Table structure as follows joined on DocKey.

mughalia_3-1622335142513.png


Expected result:

mughalia_2-1622335091346.png

 

Any help will be highly appreciated.

Thank you

1 ACCEPTED SOLUTION

Hi @Anonymous ,
If I understand you, correctly, try below. This matches your expected results, but does not include anything based on dates.  Please define what you expect from the calendar, because I am going off the rows that you highlighted with the two different colors. If this is not correct, perhaps add a correct picture?


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Distinct Count of Signee by DocNo =
VAR _curDocKey =
    MAX ( 'Fact'[DocKey] ) // Gets the current row value for DocKey
VAR _curDocNo =
    CALCULATE ( MAX ( DIM[DocNo] ), FILTER ( DIM, DIM[DocKey] = _curDocKey ) ) //Based on _curDocKey gets the DocNo
VAR _calc =
    CALCULATE ( DISTINCTCOUNT ( DIM[Signee] ), DIM[DocNo] = _curDocNo ) //filters table based on _curDocNo and returns cdistinct count
RETURN
    _calc

Capture.PNG


 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Nathaniel_C
Super User
Super User

Hi @Anonymous , the results that you show us, cannot come from your data. For example both doc 880 and 990 have only one signee in the table.  Are you trying to gather all the signees in 800s docs, and all the docs that are in the 900 range?
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi @Nathaniel_C 

Appreciate your time and let me explain it more.

1st record of fact table (DocKey 880) will find the corrsponding record (DocNo 100) in Dim, next step is to count distinct Signee against the DocNo 100 in Dim within validfrom and validto dates, given the current date. For this, Signee on record 2 and 3 will be counted resulting in count 2.

Same goes for next fact record (DocKey 990) for DocNo 300, Signee on record 4, 6 and 7 will be counted resulting in count 3.

Its like self joining Dim table.

 

mughalia_0-1622367092903.png

 

 

 

Hi @Anonymous ,
If I understand you, correctly, try below. This matches your expected results, but does not include anything based on dates.  Please define what you expect from the calendar, because I am going off the rows that you highlighted with the two different colors. If this is not correct, perhaps add a correct picture?


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

Distinct Count of Signee by DocNo =
VAR _curDocKey =
    MAX ( 'Fact'[DocKey] ) // Gets the current row value for DocKey
VAR _curDocNo =
    CALCULATE ( MAX ( DIM[DocNo] ), FILTER ( DIM, DIM[DocKey] = _curDocKey ) ) //Based on _curDocKey gets the DocNo
VAR _calc =
    CALCULATE ( DISTINCTCOUNT ( DIM[Signee] ), DIM[DocNo] = _curDocNo ) //filters table based on _curDocNo and returns cdistinct count
RETURN
    _calc

Capture.PNG


 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Great! It worked.

Thank you @Nathaniel_C 

You are welcome @Anonymous !





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.