March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
Hey everyone,
I am trying to generate a measure that filters a column with dates for those which are only from the last month or last 30 days.
I would like to use this in a calcuate function to see if the amount of rows which have the date in the last month and which meet antoher critera are greater than 0.
Thanks!
Solved! Go to Solution.
Hi @jfish29 ,
Here is the DAX to calculate the number of records with a status of closed in the last thirty days:
Count record =
CALCULATE (
COUNT ( 'Table'[status] ),
FILTER (
'Table',
[status] = "Closed"
&& [report date] <= TODAY ()
&& [report date]
>= ( TODAY () - 30 )
)
)
If you just want to know if the result is greater than 0, you can use this DAX
result =
VAR _c =
CALCULATE (
COUNT ( 'Table'[status] ),
FILTER (
'Table',
[status] = "Closed"
&& [report date] <= TODAY ()
&& [report date]
>= ( TODAY () - 30 )
)
)
RETURN
IF ( _c > 0, "Yes", "No" )
Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @jfish29 ,
Here is the DAX to calculate the number of records with a status of closed in the last thirty days:
Count record =
CALCULATE (
COUNT ( 'Table'[status] ),
FILTER (
'Table',
[status] = "Closed"
&& [report date] <= TODAY ()
&& [report date]
>= ( TODAY () - 30 )
)
)
If you just want to know if the result is greater than 0, you can use this DAX
result =
VAR _c =
CALCULATE (
COUNT ( 'Table'[status] ),
FILTER (
'Table',
[status] = "Closed"
&& [report date] <= TODAY ()
&& [report date]
>= ( TODAY () - 30 )
)
)
RETURN
IF ( _c > 0, "Yes", "No" )
Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hey, thanks for getting back!
I proabably should have offered more context about the column I want to look through. It has dates from when projects are closed, and it may not have a date within it from the last month, so I do not think the MAX function would work here?
So, it has a bunch of dates of projects which are closed, and then a placeholder value (Sunday, December 31, 1899) for all projects which are still open. Again, the goal would be to see if say, "June" is present in any cell in the column for this month.
Hi @jfish29
this a measure. MAX will only retrieve the current month visible in the filter context. Not sure what are slicing by. A screenshot of your visual will be of a great help to understand better.
The visual is a picture that gets switched by the SWITCH function depending on if the condition is met. It seems like the DAX function has to do all the calcualtions without leveraging a filter?
Hi @jfish29
can you join a zoom meeting to explain further. I sent you meeting request on private message
Here is some sample data:
We have a "report date" column which is the column i want to filter for only those dates in the past month.
Tuesday, January 18, 2022
Thursday, February 17, 2022
Sunday, December 31, 1899
Sunday, December 31, 1899
Tuesday, June 14, 2022
^ Above is the formatt of the dates in this column, the one from 1899 is a placeholder value for unfinished projects.
We have another column to filter by, called "status"
Closed
Open
^ This column holds these values
It seems to me that I need a switch function, which checks if is it is true that, there are > 0 projects within the last month that are closed.
I am using the "Image by Cloudscope" as the visualization which holds my images. It holds their values as text which I had formatted as image urls.
Hi @jfish29
I have no data to work with but this shall not be very complex
first you need to retrieve the dates in the past month:
VAR CurrentMonth = MAX ( 'Date'[Month] ) --Preferred "year month key" to avoid the previous year problem.
VAR PreviousMonthDates =
CALCULATE LTABLE (
VALUES ( TableName[Date] ),
'Date'[Month] = CurrentMonth - 1,
REMOVEFILTERS ( )
)
then you need to extract the day number of each of the available dates.
VAR T1 =
ADDCOLUMNS (
PreviousMonthDates,
"@DayNum", DAY ( [Date] )
)
then select the day number column
VAR PreviousDays =
SELECTCOLUMNS ( T1, "Day Number", [@DayNum] )
then you can calculate for example you sales amount
CALCULATE (
SUM ( TableName[Sales] ),
FILTER ( 'Date', DAY ( 'Date'[Date] ) IN PreviousDays ),
Other filters and/or calculate modifiers as required
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
15 | |
12 | |
9 | |
8 |
User | Count |
---|---|
41 | |
32 | |
29 | |
12 | |
12 |