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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
monicaalves4
Regular Visitor

Count rows in the period between dates

Hi,

 

I have a table similar to the table below and I would like to make a measure that calculates how many items there are with today's and yesterday's created date.

monicaalves4_2-1673290572599.png

 

I started by using the following formula

 

CALCULATE(COUNT('items'[CreatedDate]),'items'[CreatedDate]>Today,'items'[Type]="Type 1").
 
This formula gives me a measure with total items of "Type 1" and created today. Now I would like that give me back the itens today and yesterday what do I need to change? what if i want the ones created in the last 3 days or during this week?
 
Thank you!
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new measure.

 

Jihwan_Kim_0-1673291561541.png

 

Items count from one day before to today: =
CALCULATE (
    COUNTROWS ( Data ),
    Data[Type] = "Type1",
    Data[CreatedDate]
        >= TODAY () - 1
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @monicaalves4 

According to your description, you want to get the count of items which type = "Type1" and you want to make the calculation dynamic? Like last n days?

Here are the steps you can refer to :
(1)We can create a what-if parameter as a slicer:

vyueyunzhmsft_0-1673314846078.png

vyueyunzhmsft_1-1673314858064.png

(2)Then we can create a measure like this:

Measure = 
var _slicer= [Parameter Value]
var _first_day = TODAY()- _slicer+1
var _t =  FILTER('Table', 'Table'[Type]="Type1" && 'Table'[CreatedDate]>= _first_day && 'Table'[CreatedDate]<=TODAY())
return
COUNTROWS(_t)

(3)Then we can meet your need , when we select the slicer n, it means we get the count of the items in the last n days:

vyueyunzhmsft_2-1673315067823.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

FreemanZ
Super User
Super User

hi @monicaalves4 

In addition to Jihwan's solution, you may also try:

 

CountMeasure =

COUNTROWS(

    FILTER(

         items, items[CreateDate]>=TODAY()-1

             &&items[Type]="Type1"

     )

)

 

pls replace 1 with 2, to get the last 3 days count; 1 with 6, to get the last week count.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new measure.

 

Jihwan_Kim_0-1673291561541.png

 

Items count from one day before to today: =
CALCULATE (
    COUNTROWS ( Data ),
    Data[Type] = "Type1",
    Data[CreatedDate]
        >= TODAY () - 1
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Top Solution Authors