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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Neqom
Frequent Visitor

Count Based on Date in the same Table

I have a Table with the below structure:

ID - Date

1 - 1/Jan/2020
1 - 2/Jan/2020
2 - 1/Jan/2020
3 - 1/Jan/2020
4 - 5/Jan/2020
...

Where ID appears multiple times. I need a measure in a Table Visual where a new column called "Last  30 days" shows the amount of entries of the table in the last 30 days

ID - Amount
1 - 2
2 - 1
3 - 1
4 - 1

Important to note that I can't add a filter to the visual since the visual contains more data. Like ID that have no entries in the last 30 days or other information that if I add the filter will be remove from the visual. Also the full visual has information from multiple tables.

I need something like Count(ID) where Date+30>=Today()

1 ACCEPTED SOLUTION

Hi @Neqom ,

Here's my modified data, otherwise unchanged.

vhuijieymsft_1-1715927922598.png

 

Just select Show item with no data in the ID field and now, IDs with no counts in the last 30 days show blank.

vhuijieymsft_0-1715927866129.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

5 REPLIES 5
v-huijiey-msft
Community Support
Community Support

Hi @Neqom ,

 

Thanks for the reply from Awm .

 

First, create a measure to store your definition of today=2020/1/10:

_today = DATE(2020,1,10)

 

Then, create a measure to count the number of rows:

Count = CALCULATE(
        COUNTROWS('Table'),
        FILTER(
            'Table'.
            'Table'[Date] >= [_today] - 30 && 'Table'[Date] < [_today]
        )
    )

 

The page visualization is shown below:

vhuijieymsft_0-1715061439915.png

 

If you want to calculate the last 30 days of data for today (2024/05/07), you can replace _today with Today().

Count = CALCULATE(
        COUNTROWS('Table'),
        FILTER(
            'Table',
            'Table'[Date] >= TODAY() - 30 && 'Table'[Date] < TODAY()
        )
    )

 

The pbix file is attached.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hello!
Thanks for your help.
Iy works. however it shows blank instead of "0" for ID where there is nothing in the last 30 days
Sorry for no specify that at the beginning.


Hi @Neqom ,

Here's my modified data, otherwise unchanged.

vhuijieymsft_1-1715927922598.png

 

Just select Show item with no data in the ID field and now, IDs with no counts in the last 30 days show blank.

vhuijieymsft_0-1715927866129.png

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Awm
Frequent Visitor

Last 30 Days =
VAR MaxDate = MAX('YourTable'[Date])
VAR MinDate = MAX('YourTable'[Date]) - 30
RETURN
CALCULATE(
COUNTROWS('YourTable'[Date]),
'YourTable'[Date] >= MinDate && 'YourTable'[Date] <= MaxDate
)

Neqom
Frequent Visitor

Note* Example asuming that Today = 10/Jan/2020

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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