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

View all the Fabric Data Days sessions on demand. View schedule

Reply
swisdom
Helper I
Helper I

Distinct count of lines meeting certain criteria

Link to raw data sample 
Link to sample PBI file 

 

I have a PBI that contains a bunch of RMA entries with various date fields. I am looking to build a measure which will give me a "Units In House" at the end of each month. ON the last day of the month, it should give a count of the lines in which the "Date Received" is BEFORE that date, and the "Actual Ship Date" Is either AFTER that date, or blank. (AKA the units which have been received, but not yet shipped, as of the last day of the month).

My DAX code:

 

Units In House = 
var dt = endofmonth('Date'[Date])
return
calculate( 
    calculate(distinctcount('Table1'[NCR_ID]), 
    'Table1'[Date Received]<=dt , or(isblank('Table1'[Date Actual Ship]), 'Table1'[Date Actual Ship]>dt ) ),
    crossfilter( 'Date'[Date],'Table1'[Date Received],None ) )

 

The crossfilter at the end is being used to break the model relationship between Date Received and Date (so that it isnt only giving those which were received in that month).

swisdom_0-1638894108585.png

I wanted to have someone double check my code is actually doing what I want it to be doing, because I am getting higher numbers than I would expect (by about double). Thoughts?

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @swisdom ,

 

Is this the result you expect?

Units In House 2 = 
VAR dt =
    ENDOFMONTH ( 'Date'[Date] )
RETURN
    CALCULATE (
        CALCULATE (
            DISTINCTCOUNT ( 'Table1'[NCR_ID] ),
            'Table1'[Date Received] <= dt,
            OR ( ISBLANK ( 'Table1'[Date Actual Ship] ), 'Table1'[Date Actual Ship] > dt )
        ))

Icey_0-1640161986007.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

I have, there are links at the top of my post.

Icey
Community Support
Community Support

Hi @swisdom ,

 

Is this the result you expect?

Units In House 2 = 
VAR dt =
    ENDOFMONTH ( 'Date'[Date] )
RETURN
    CALCULATE (
        CALCULATE (
            DISTINCTCOUNT ( 'Table1'[NCR_ID] ),
            'Table1'[Date Received] <= dt,
            OR ( ISBLANK ( 'Table1'[Date Actual Ship] ), 'Table1'[Date Actual Ship] > dt )
        ))

Icey_0-1640161986007.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors