Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

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!

  • 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.


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

    Greetings,
    Esteban




  • 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.

    filter pane 

     

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

15 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

    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?

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      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
      • vanessafvg's avatar
        vanessafvg
        Community Champion

        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

         

         

  • 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
    • Anonymous's avatar
      Anonymous
      Not applicable

      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

      • Syndicate_Admin's avatar
        Syndicate_Admin
        Administrator

        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.


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

        Greetings,
        Esteban