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
davidi4524
Helper III
Helper III

count number of selected month in specific year

hi , i have a data of 

custname

partname

quant

month

year

i added with power bi a date month and year table that related to the first table.

now i whant to select a multiple period by year 2017 - 2016

i what to get two columns that will show :

number of month selected from 2016

and number of month selected from 2017

its somthing like countif in excel - if the year of the selected month is 2016 count to measure a

and if the year of the selected month is 2016 count to measure b.

how to do this? im shure its very simple 🙂

thanks for help.

7 REPLIES 7
v-shex-msft
Community Support
Community Support

Hi @davidi4524,

 

Perhaps you can try to write a measure to get the current date and use this date find out the previous year value.

 

Sample:

Current/Pervious = 
var currDate=MAX(Table[Date])
return
COUNTAX(FILTER(ALL(Table),[Date]=currDate),[ColumnName])+0 &"/"&
COUNTAX(FILTER(ALL(Table),[Date]=DATE(YEAR(currDate)-1,MONTH(currDate),DAY(currDate))),[ColumnName])+0

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
DoubleJ
Solution Supplier
Solution Supplier

Hi

 

I have an approach that might help you. I assumed that in the calendar table is one entry for each month (e.g. always the first day of the month).

 

Create 2 measures for 2016 and 2017 respectively:

SelectedMonths2016 = COUNTX(FILTER('Calendar';YEAR('Calendar'[Date])= 2016);'Calendar'[Date])
SelectedMonths2017 = COUNTX(FILTER('Calendar';YEAR('Calendar'[Date])= 2017);'Calendar'[Date])

That should do the trick:

MonthSelection_01.PNG

 

 

I hope this helps!

JJ

 

?

Please have a try with this formula (you might have to replace the semicolons with commas):

 

SelectedMonths2016 = CALCULATE(
     DISTINCTCOUNT('Calendar'[Date].[Month]);
     FILTER('Calendar';YEAR('Calendar'[Date])= 2016);'Calendar'[Date])

Does this work?

 

its work but its count all the month of the year, i whant to coumt only the selected months by the filter.

you can solve it?

Why don't you use a Matrix instead of table. Try years on rows and count of months on value.


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

Happy to help!

LaDataWeb Blog

this its look like this after i put you syntax: somthing wrong with the numbers.the calendare table have the folowing columns:date month year.what did i do wrong?

tselected months2016.PNG

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.