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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PBI_newuser
Post Prodigy
Post Prodigy

Distinct count of Serial number if falls within the date range

Hi, 

How to calculate the distinct serial numbers that having start date and end date falling between the selected created date range?

 

For example: Distinct count of serial number = 6 - 2 (out of the range) = 4

Capture.PNG

1 ACCEPTED SOLUTION

Hi @PBI_newuser ,

 

Try to create a measure like this:

Measure = 
CALCULATE (
    DISTINCTCOUNT ('Table'[id] ),
    GENERATE (
        VALUES ( 'Table 2'[Date] ),
        FILTER (
            'Table',
            CONTAINS (
                DATESBETWEEN (
                    'Table 2'[Date],
                    'Table'[Created date],
                    'Table'[Closed date]
                ),
                'Table 2'[Date],'Table 2'[Date]
            )
        )
    )
)

  Sample .pbix 

 

 

Best Regards,
Liang
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

11 REPLIES 11
V-lianl-msft
Community Support
Community Support

Hi @PBI_newuser ,

 

What do you mean? Has the previous problem been solved? Or do you mean the new problem?

If it is a new problem, could you describe more information to let me know your scenario

 

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

Hi @V-lianl-msft,

Yea, the previous problem is solved.

How can I modified the below measure by using the Datesbetween logic?

SN Count Exist in Table B =
VAR t =
        FILTER (
        'Product',
        'Product'[Start Date] <= MIN ( 'Table'[Date] )
            && 'IProduct'[End Date] >= MAX ( 'Table'[BD Notified Date])
    )
RETURN
     CALCULATE(DISTINCTCOUNT('Product'[Serial Number]),FILTER (t, [Serial Number] IN VALUES ( 'Table B'[Serial Number] ) ) )

 

 

 

Hi @PBI_newuser ,


Based on the formula previously provided .

Try to use if statement or add filter condition :

IF(MAX('Table A'[Serial Number]) IN VALUES ( 'Table B'[Serial Number] ) ,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX)

OR

xxxxxxxxxxxxxxxx,FILTER(Table A,'Table A'[Serial Number] IN VALUES ( 'Table B'[Serial Number] ))

 

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

Thanks @V-lianl-msft !

As advised, I have created the calendar table and create relationship with the [Created Date] in 'Table'.

Why I can't create the "period" by using [Created Date] anymore?
The calendar logo is disappeared beside the [Created Date] field.

 

Period = 'Table'[Created Date].[Year] & "-" & FORMAT('Table'[Created Date].[Date],"MM") 

Hi @PBI_newuser ,

 

Actually, when you create the relationship (Many to one or one to Many) between the tables with Date, only the date in the one side will show date hierarchy. 

Try:

period = FORMAT('Table (2)'[date],"YYYY-MM")

 

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

amitchandak
Super User
Super User

@PBI_newuser , check if the attached file can help

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak ,

If year 2020 is selected, the count should be 4. (a,b,c,d start & end date touch the selected month)

If year 2020 month June is selected, the count should be 2.

 

How to modify the logic?

 

Count serial number if the range of start and end date touch selected range of "Created Date".

 

Thanks.

Hi @PBI_newuser ,

 

Try to create a measure like this:

Measure = 
CALCULATE (
    DISTINCTCOUNT ('Table'[id] ),
    GENERATE (
        VALUES ( 'Table 2'[Date] ),
        FILTER (
            'Table',
            CONTAINS (
                DATESBETWEEN (
                    'Table 2'[Date],
                    'Table'[Created date],
                    'Table'[Closed date]
                ),
                'Table 2'[Date],'Table 2'[Date]
            )
        )
    )
)

  Sample .pbix 

 

 

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

Hi @V-lianl-msft,

 

I have tried the below measure but it shows the below error.

May you assist why this happened?

Capture.PNG

Measure =
CALCULATE (
    DISTINCTCOUNT ('Product'[Serial Number]),
    GENERATE (
        VALUES ('Table'[Created Date]),
        FILTER (
            'Product',
            CONTAINS (
                DATESBETWEEN (
                   'Table'[Created Date],
                    'Product'[Start Date],
                    'Product'[End Date]
               ),
              'Table'[Created Date],'Table'[Created Date]
            )
        )
    )
)

 

Hi @PBI_newuser ,

 

Try to create a calendar table and create relationships

 

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

Hi @V-lianl-msft ,
How can I have one more measure to exclude those Serial Number exist in the other table with the same logic?


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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