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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
CosmicHorse95
Advocate I
Advocate I

Count Rows Range of Years

Hello,

 

I'm trying to use my data to create some different pie charts and bar graphs.

 

My data set consists of the years 2009 through 2020. The data of interest is strains of a virus, and how many occurances we have of each strain per year.

 

I've created several measures (Strain A 2010, Strain B 2010, Strain A 2011, Strain B 2011, etc etc) as well as a bunch of countrows DAX that counts Strain A from the entire database, Strain B from the entire database, etc.

 

Now what I want to do is create a measure that will "countrows" from a range of years (2009-2014, 2015-2020).

Basically looking to create: Measure=Calculate(countrows('table'), 'table'[column]="2009-2014") But obviously this exact thing doesn't work.

*Where [column] is [Year]

 

Any help is greatly appreciated!

2 ACCEPTED SOLUTIONS

Hello again

Sorry if you didn't explain me better,

IF(YEAR(Calendar[Date]) >= 2015 && YEAR(Calendar[Date]) <= 2020, "True","False")

"Calendar" you must change it to the name of the database, "Date" should change it to the column where you have specified the year.

As I have seen in the capture of the other message that you have answered you have the column called "Year" and you only have the year indicated, so you should change the calculated columns that I told you before as follows:

2009 a 2014:
Rango2009-2014 = IF("Nombre_Base_Datos"[Año] >= 2009 && "Nombre_Base_Datos"[Año] <= 2014, "True","False")

2015-2020:
Range2015-2020 = IF"Nombre_Base_Datos"[Year] >= 2015 && "Nombre_Base_Datos"[Year] <= 2020, "True","False")

I will attach a couple of screenshots indicating how to create the calculated columns to make everything clearer.

I've replicated the example you've posted to try to help you as much as possible.

EstebanGM_0-1663185443858.png


I hope it has become clearer and if it has helped you do not forget to score!

Greetings,
Esteban




View solution in original post

there a variety of ways you can do this.  Pie charts are not that easy to do comparisons, either clustered or stacked bar charts are easier.    If you decide to use the 2 pie charts, you need to filter the group-range calculated column in the filter pane to select the group you want in that chart.

vanessafvg_0-1663228601499.png

filter pane 

vanessafvg_1-1663228752445.png

 

i re attach the file with the visuals in them, and yes this is the same calculated column i created with the count measure





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

15 REPLIES 15
Syndicate_Admin
Administrator
Administrator

Good CosmicHorse95,

This is my first post on the forum and I hope I can help you.

You can try to do this with calculated columns as follows:

If you want the ranges of:
2009 to 2014:

Rango2009-2014 = IF(YEAR(Calendar[Date]) >= 2009 && YEAR(Calendar[Date]) <= 2014, "True","False")

2015-2020:
Range2015-2020 = IF(YEAR(Calendar[Date]) >= 2015 && YEAR(Calendar[Date]) <= 2020, "True","False")

These calculated columns can be used in the "Count" mode fields and put a filter that only tells you those that are in "True"

In this way you will be able to calculate the total of lines according to the range of year you have indicated.

Greetings,
Esteban

Hi Esteban, 

Thank you for your help, though i'm afraid I'm not sure how to use the formulas you provided. What is calendar? How do i create a calculated column?

 

I'm so sorry for the trouble! Thank you

Hello again

Sorry if you didn't explain me better,

IF(YEAR(Calendar[Date]) >= 2015 && YEAR(Calendar[Date]) <= 2020, "True","False")

"Calendar" you must change it to the name of the database, "Date" should change it to the column where you have specified the year.

As I have seen in the capture of the other message that you have answered you have the column called "Year" and you only have the year indicated, so you should change the calculated columns that I told you before as follows:

2009 a 2014:
Rango2009-2014 = IF("Nombre_Base_Datos"[Año] >= 2009 && "Nombre_Base_Datos"[Año] <= 2014, "True","False")

2015-2020:
Range2015-2020 = IF"Nombre_Base_Datos"[Year] >= 2015 && "Nombre_Base_Datos"[Year] <= 2020, "True","False")

I will attach a couple of screenshots indicating how to create the calculated columns to make everything clearer.

I've replicated the example you've posted to try to help you as much as possible.

EstebanGM_0-1663185443858.png


I hope it has become clearer and if it has helped you do not forget to score!

Greetings,
Esteban




Thanks Esteban! The screenshots were super helpful!

 

Do you know if there's any way to use that column then to make a pie chart?

The goal is to make a pie chart that consists only of the data that falls between those ranges (2009-2014 and 2015-2020), but that includes the strains. As of now, when I try to make a pie chart with 2009-2014 column, and "strain" as the legend, I still get all the data from the entire spreadsheet.

 

I don't know if I explained that clearly, I'm sorry in advance

 

vanessafvg
Super User
Super User

can you provide a sample of your data?    Its hard to know what to advise without knowing what it looks like, also provide it in text form.

 

What are you trying to achieve, what is the goal?  insight?

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




I am not trying to be rude, but I answered all your questions in my own question.

I apologize, I can see some areas where I wasn't super clear. Forgive me.

 

I'm trying to make a DAX that will count the number of rows through multiple years. I want it to count all the rows that include the years 2009, 2010, 2011, 2012, 2013, and 2014 in the [Year] column.

 

The goal is to create visuals with this information. Using only the data in the selected range, and counting/evaluating the strains with the selected data. 

 

It is difficult to provide sample data when the data is confidential, but i did my best.

 

YearSample NameAgeStrainStrain 2Final CallStrain D Variety?Hybrid?Classic?
2009Sample #121Strain A Strain ANoNoNo
2009Sample #221Strain A Strain AYesNoNo
2009Sample #321Strain A Strain AYesYesNo
2009Sample #421Strain C Strain CYesYesNo
2009Sample #521Strain E Strain EYesYesNo
2010Sample #621Strain B Strain BYesYesNo
2010Sample #721Strain B Strain BNoNoNo
2010Sample #821Strain D Strain DNoNoNo
2010Sample #921Strain D Strain DNoNoNo
2011Sample #1021Strain E Strain ENoNoNo
2011Sample #1121Strain F Strain FNoNoNo
2011Sample #1221Strain F Strain FNoNoNo
2011Sample #1321Strain F Strain FNoNoNo
2011Sample #1421Strain A Strain ANoNoNo
2011Sample #1521Strain C Strain CNoNoNo
2011Sample #1621Strain A Strain ANoNoNo
2013Sample #1721Strain A Strain ANoNoNo
2013Sample #1821Strain A Strain ANoNoNo
2013Sample #1921Strain F Strain FNoNoNo
2014Sample #2021Strain E Strain ENoNoYes
2014Sample #2121Strain E Strain ENoNoNo
2014Sample #2221Strain B Strain BNoNoNo
2014Sample #2321Strain B Strain BNoYesNo
2015Sample #2421Strain B Strain BNoNoNo
2015Sample #2521Strain A Strain ANoNoNo
2015Sample #2621Strain A Strain ANoNoNo
2015Sample #2721Strain A Strain AYesNoNo
2016Sample #2821Strain A Strain ANoNoNo
2016Sample #2921Strain A Strain ANoNoNo
2017Sample #3021Strain F Strain FYesNoNo
2017Sample #3121Strain F Strain FNoNoNo
2018Sample #3221Strain B Strain BNoNoNo
2019Sample #3321Strain B Strain BYesYesNo
2019Sample #3421Strain E Strain ENoNoNo
2020Sample #3521Strain E Strain ENoNoNo
2020Sample #3621Strain C Strain CNoNoNo

well not trying to be rude back, but you did not provide the data.  No one can really give you accurate advice without knowing what your data looks like. 

 

If you read the advisory post at the top of this forum it says that if you want to get your questions quickly provide as much info as possible, and  you should provide sample data.  

 

Is this what you are looking for?  You can create a calculated column on your table with a switch statement.  Similar to what is above.   see pbix attached

 

vanessafvg_0-1663190061905.png

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




wouldn't it be easier to read as a bar chart?  

vanessafvg_1-1663193475811.png

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




vanessafvg_0-1663193394758.png

?

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




what is it that you are wanting to show on a pie chart?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




I agree, I like the column/bar charts myself. Unfortunately, in reality there are more than 7 strains and the bar graphs get extremely cluttered like that, and my supervisor doesn't like them as much as the pie charts.

**I'm dumb, I was looking at the image all wrong. The clustered column that you have might actually be better than the pie charts! Is that utilizing the same measurement that you originally shared with me?

 

Ideally, two different pie charts. 

 

Pie Chart 1: Shows the count of each strain between years 2009 and 2014

Pie Chart 2: Shows the count of each strain between years 2015 and 2020

 

Does that makes sense? Maybe I'm not explaining it very well. I'm sorry I can't show you the complete data to fill in the gaps.

there a variety of ways you can do this.  Pie charts are not that easy to do comparisons, either clustered or stacked bar charts are easier.    If you decide to use the 2 pie charts, you need to filter the group-range calculated column in the filter pane to select the group you want in that chart.

vanessafvg_0-1663228601499.png

filter pane 

vanessafvg_1-1663228752445.png

 

i re attach the file with the visuals in them, and yes this is the same calculated column i created with the count measure





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Thank you so so much for walking me through this!!! This is perfect!

This is almost exactly what I'm looking for, but my goal is to have two separate pie charts. Can the measurement be split to have the two individual ranges?

 

Oops, I apologize, I just saw this response. 

I just amended my first reply to you trying to offer a little more detail. You're right, in hindsight I didn't provide as much detail as I thought I was. 

 

I really appreciate your time and help

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.