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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filter open and old data and show in a table visual

Hi,

 

I have a series of orders, and I want to build a measure to get those entries that satisfy the following conditions:

 

  1. Are older than 30 days (i.e. they are before the 1st day of the previous month)
  2. Status is open

 

I have Data table and Date table which are related together. Example of data are:

 

DateIDStatus
13/11/20211Open
01/11/20212Close
23/10/20213Open
12/10/20214Open
02/10/20215Close
20/09/20216Open
19/09/20217Close
10/09/20218Close

 

When using date filter:

 

If a date in December is selected:

1st day of previous month is 1 Nov 2021, thus open ones in Oct and Sep should be returned: rows 3, 4, 6

 

If a date in November is selected:

1st day of previous month is 1 Oct 2021, thus open ones in Sep should be returned: row 6

 

Note: I need a measure so that I can use it to filter a table visual which shows those open and old entries.

 

I have used this, but not working:

Open Orders =
VAR First_Day_Previous_Month = EOMONTH(LASTDATE('Date'[Date]),-2)+1
VAR Countt = CALCULATE(DISTINCTCOUNT('Data'[ID]))
RETURN
CALCULATE([Countt], FILTER('Data', 'Data'[Date] < First_Day_Previous_Month))
 
Please help me doing this task.
Thanks
9 REPLIES 9
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here's my solution.

1.Create a calendar table.

Calendar = ADDCOLUMNS(CALENDAR(DATE(2020,1,1),DATE(2021,12,21)),"Year",YEAR([Date]),"Month",MONTH([Date]))

vstephenmsft_0-1637652082306.png

2.Create a measure and put it into filters. Set show items when the value is 1.

Measure = IF(ISFILTERED('Calendar'[Month]),IF(MAX('Table'[Date])<DATE(SELECTEDVALUE('Calendar'[Year]),SELECTEDVALUE('Calendar'[Month])-1,1)&&MAX('Table'[Status])="Open",1),1)

vstephenmsft_1-1637652216172.png

 

When you select December 2021 in the slicer, the result is as follows.

vstephenmsft_2-1637652237226.png

When November 2021 is selected.

vstephenmsft_3-1637652284039.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

Anonymous
Not applicable

Thank you very much for your creative solution.

 

I actually have a big model that date table is related to data table. So, they are not separated.

In this condition, this equation seems to be not working.

In addition, do you believe this solution works if the date is accross two years? Does it work if we choose a data in January or February?

 

More data to test:

 

DateIDStatus
2022/02/151Open
2022/02/102Close
2022/01/193Open
2022/01/84Close
2021/12/255Open
2021/12/026Close
2021/11/137Open
2021/11/18Close
2021/10/239Open
2021/10/1210Open
2021/10/211Close
2021/9/2012Open
2021/9/1913Close
2021/9/1014Close

Hi @Anonymous ,

 

I modified the measure, and the slicer puts the date column of the calendar table.

Measure = IF(MAX('Table'[Date])<=EOMONTH(SELECTEDVALUE('Calendar'[Date]),-2)&&MAX('Table'[Status])="Open",1)

vstephenmsft_0-1638948150139.png

vstephenmsft_1-1638948198637.png

vstephenmsft_2-1638948209180.png

 

 

Best Regards,

Stephen Tao

 

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

Anonymous
Not applicable

Thanks so much for your help.

 

I have related tables, and the solution seems to be not working with it.

 

Regards

Anonymous
Not applicable

I don't understand why this measure doesn't work:

 

measure = CALCULATE(DISTINCTCOUNT('Table'[ID]), DATESBETWEEN('Date'[Date], FIRSTDATE('Date'[Date]), ENDOFMONTH(DATEADD(LASTDATE('Date'[Date]), -2, MONTH))), FILTER('Table', MAX('Table'[Status])="Open"))
 
Then using it as a filter and say measure > 0             😞
 
 
 
Any solution please?
Jihwan_Kim
Super User
Super User

Hi,

I suggest having a disconnected calendar table like below.

Please check the below picture and the attached pbix file.

 

Picture1.png

 

Status measure: =
VAR selectedmonthnumber =
MAX ( 'Calendar'[Month number] )
VAR previousmonthnumber = selectedmonthnumber - 1
VAR datesincondition =
SUMMARIZE (
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Month number] < previousmonthnumber ),
'Calendar'[Date]
)
RETURN
IF (
HASONEVALUE ( Data[Date] ),
MAXX (
FILTER ( data, Data[Date] IN datesincondition && Data[Status] = "Open" ),
Data[Status]
)
)

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


Anonymous
Not applicable

Thank you so much.

 

I actually cannot break the relations.

They are all part of a huge dataset and model.

 

If you have any other solutions, please let me know.

That would be greatly appreciated. 

ryan_mayu
Super User
Super User

@Anonymous 

pls see the attachment below. Hope it's helpful.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks.

It seems that the solution does not fully work.

There are some issues:

 

  1. If date is across two years (for example selected date is in January or February, this does not work.
  2. The two tables are not related. I have a big model in which the date and data tables are related on date.

 

Kindly let me know if you have any other solution.

---------------------

As a test, I'm trying to add another column which shows recent/old events per row. But it is NOT working correctly (Maybe because of having a relation). 

 

Old - Recent =
VAR First_Day_Previous_Month = EOMONTH(LASTDATE('Date'[Date]),-2)+1
RETURN
IF(MAX('Table'[Date]) < First_Day_Previous_Month, "old", "recent")

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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