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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

filter column with month and year only

I want filter column Start(Date) only month and year.

Not mind date.

 

How to edit query? 

 

VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before ',
'Before'[Start(Date)] = "15/1/2564"
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )
1 ACCEPTED SOLUTION

@Anonymous 

Just change the column back to text and use the code I gave you that works with dates stored as text

Measure = VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before',
AND ( YEAR(DATEVALUE('Before'[Start(Date)])) = 2021 , MONTH(DATEVALUE('Before'[Start(Date)])) = 12 )
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

11 REPLIES 11
PhilipTreacy
Super User
Super User

Hi @Anonymous 

You need to use DATEVALUE to convert those text values into proper dates

Measure = VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before',
AND ( YEAR(DATEVALUE('Before'[Start(Date)])) = 2021 , MONTH(DATEVALUE('Before'[Start(Date)])) = 12 )
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Anonymous 

Without seeing the data I can't do any more.  I don't know what these dates stored as text look like.  Are they 1 Dec 21, or 1st December 2021 or 1/12/2021 etc?

That's why you should always supply some sample data.

Can you not just change the column to Date type?

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy  Now I change format type to Date. 

But I use your query  but not found data.

 adamasmay_1-1611831040890.png

adamasmay_2-1611831227926.png

It value in care show 0 

adamasmay_3-1611831307412.png

 

 

@Anonymous 

Year needs to be a 4 digit number

Month is a number from 1 to 12

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy  Change in format or measure?

 

adamasmay_0-1611833629733.png

Now format value dd/mm/yy

@Anonymous 

Just change the column back to text and use the code I gave you that works with dates stored as text

Measure = VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before',
AND ( YEAR(DATEVALUE('Before'[Start(Date)])) = 2021 , MONTH(DATEVALUE('Before'[Start(Date)])) = 12 )
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy  If I change the requirement to not year=2021 , month not = 12 and column not blank measure as below.

It error

Measure 2 = VAR __CurrentMeasure =
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER ('Before',
AND ( YEAR(DATEVALUE('Before'[Start(Date)])) <> 2021 , MONTH(DATEVALUE('Before '[Start (Date)])) <> 1 , 'Before '[Start(Date)] <> BLANK())
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

It error : Too many arguments were passed to the AND function. The maximum argument count for the function is 2.

 

 

PhilipTreacy
Super User
Super User

Hi @Anonymous 

OK, you can use this,

Measure = VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before',
AND ( YEAR('Before'[Start(Date)]) = 2021 , MONTH('Before'[Start(Date)]) = 12 )
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy Value in start date are format text.

adamasmay_0-1611829837826.png

 

adamasmay_1-1611830081136.png

 

 

 

PhilipTreacy
Super User
Super User

Hi @Anonymous 

Download this sample PBIX file with the following data and code

So you just want to count the number of dates equal to (or before) a specific date?

Please, always supply some sample data and your expected result.

Using this data

filter-dates.png

To count the number of dates before 1 Dec 2021 you can use this

 

Measure = VAR __CurrentMeasure = 
CALCULATE (
COUNT ( 'Before'[Start(Date)]),
FILTER (
'Before',
'Before'[Start(Date)] < DATE(2021,12,1)
)
)
RETURN
IF ( ISBLANK ( __CurrentMeasure ), 0, __CurrentMeasure )

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy I want to count the number specific december 2021 only , never mind date

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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