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

Be 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

Reply
MaNUEL2019
New Member

How to count records in a range dates per month

Hi Guys, 

Maybe you can help me on this...

I want to know how many machines per month I have in a customer based on this table

machine Serial numberCustomerInit dateEnd date
42509A01/01/201930/03/2109
42509B01/04/201918/02/2020
42510A01/02/2019 
87836C01/01/2019 

 

I want to have a result like this...

 Customer A   
 ene-19feb-19mar-19abr-19may-19
Machines12211

I have tried with summarize but I cannot adjust by period... 

Any help...

 

Thanks in advance

Regards.

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @MaNUEL2019 

 

Firstly, you can create a calculated table as follows.

Dates = CalendarAuto()

 

Secondly, you may create two columns and a measure as below.

FormatDate = FORMAT([Date],"MMM") & "-" & FORMAT('Dates'[Date],"YY")

Machines = "Machines"

Amount =

CALCULATE (

    DISTINCTCOUNT ( 'Table'[machine Serial number] ),

    FILTER (

        FILTER(ALLSELECTED ( 'Table' ),'Table'[Customer] IN FILTERS ( 'Table'[Customer] )),

        OR (

            [Init date] <= MAX ( 'Dates'[Date] )

                && ISBLANK ( 'Table'[End date] ),

            NOT (

                OR ( [Init date] >= MAX ( 'Dates'[Date] ), [End date] <= MIN ( 'Dates'[Date] ) )

            )   

        )

    )

)

 

Result:

xx.png

If I misunderstand your thought, please show me your expected output. I am glad to solve the problem.

 

Best Regards,

Allan

 

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

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @MaNUEL2019 

 

Firstly, you can create a calculated table as follows.

Dates = CalendarAuto()

 

Secondly, you may create two columns and a measure as below.

FormatDate = FORMAT([Date],"MMM") & "-" & FORMAT('Dates'[Date],"YY")

Machines = "Machines"

Amount =

CALCULATE (

    DISTINCTCOUNT ( 'Table'[machine Serial number] ),

    FILTER (

        FILTER(ALLSELECTED ( 'Table' ),'Table'[Customer] IN FILTERS ( 'Table'[Customer] )),

        OR (

            [Init date] <= MAX ( 'Dates'[Date] )

                && ISBLANK ( 'Table'[End date] ),

            NOT (

                OR ( [Init date] >= MAX ( 'Dates'[Date] ), [End date] <= MIN ( 'Dates'[Date] ) )

            )   

        )

    )

)

 

Result:

xx.png

If I misunderstand your thought, please show me your expected output. I am glad to solve the problem.

 

Best Regards,

Allan

 

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

KEITHO
Frequent Visitor

I don't think you will be able to do it until you reformat the data.

Each date between init date and end date will have to be associated to the customer and machine serial number. So for example your data should have 89 records for machine serial 42509 for customer A. Alternatively you need at least one record per month present.

 

You can do that with a linked date range table. There's another post here which gives a pretty good outline of using dates:

https://community.powerbi.com/t5/Desktop/Group-dates-to-Month/m-p/166986#M72916

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.