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

Count rows based on Month and year comparison

 Hi All,

 

I have a single table with 2 date fields:

  • Report Date: The date on which the data table was created... the 1st of every month
  • Created On: The date that each row within the data table was created.

Report Date    Created on    Count

01/03/201910/03/2019Y
01/03/201906/05/2015N
01/04/201904/08/2016N
01/04/201920/04/2019Y
01/04/201905/04/2019Y

The logic I need is: Count IF "Created On" Month and Year = "Report date" Month and Year.

What is the best method of creating this?

Thank you in advasnce for any help.

Moby

1 ACCEPTED SOLUTION

Hi @Anonymous 

You may create a column like below and then create a measure to get the count.

Column = 
IF (
    MONTH ( 'Table'[Report Date] ) = MONTH ( 'Table'[Created On] )
        && YEAR ( 'Table'[Report Date] ) = YEAR ( 'Table'[Created On] ),
    "Y",
    "N"
)
Measure =
COUNTROWS ( FILTER ( 'Table', NOT ( 'Table'[Analysis] ) IN { "CLSD" } ) )

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Update: I have managed to get to this point by adding 2 columns which format the date into year and month:

Untitled.png

Now I just need to figure out how to write the IF statement to compare the 2 dates and count all rows not including "CLSD".... I'm still struggling, so I would appreciate any help.

 

This Calcualted colunm will give you a 1 or a 0 based on the two dates 

you can then sum this colunm as a measure to get what your after

 

Column =
Var Ry = year(Table1[Report Date]) --get report year
Var rm = month(Table1[Report Date]) --get report month
Var cy = year(Table1[Created date]) --get created year
Var cm = MONTH(Table1[Created date]) --get created month
var checky = ry = cy --compare Report and created year and return true or false
var checkm = rm = cm --compare Report and created month and return true or false
-- Check that both results are True if so then 1 else 0
Var ret = if(and(checkm,checky),1,0)
Return ret

compare.png




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

Proud to be a Super User!




Hi @Anonymous 

You may create a column like below and then create a measure to get the count.

Column = 
IF (
    MONTH ( 'Table'[Report Date] ) = MONTH ( 'Table'[Created On] )
        && YEAR ( 'Table'[Report Date] ) = YEAR ( 'Table'[Created On] ),
    "Y",
    "N"
)
Measure =
COUNTROWS ( FILTER ( 'Table', NOT ( 'Table'[Analysis] ) IN { "CLSD" } ) )

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi Cherie, Thank you for the response, your solution was perfect for the question that I asked so I have accepted it as the correct solution.... the only problem is, I asked the wrong question. I will close this thread while I think about it a bit more. Thanks Moby

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.