Forum Discussion

inglexjc's avatar
inglexjc
Post Patron
1 year ago
Solved

Age Bins

I've created an Age Bin but it's not working correctly.  Code I'm using is:

 

Age Bins = SWITCH(TRUE(),'Legal Files'[Child Age]=BLANK(),"0",'Legal Files'[Child Age]<=1, "<1",'Legal Files'[Child Age]<=5, "1-5",'Legal Files'[Child Age]<=10, "5-10",'Legal Files'[Child Age]>=10, "Older than 10")

 

And get this:

 

The problem is for 8/6/2025 the we have a child age 1 and 3 and the 1 year old is showing in the <1 group.

 

And yesterday we had a child age 0 that wasn't showing up in the graph at all

 

 

I'm not sure why BLANK is being used in the age bin, I think that can be taken out becuase a child's age will never be blank.  Help is appreciated.

 

  • As per your condition, Age 0 is <1 as you used <=1 instead of <1.  Also, shouldn't it be 6-10 instead of 5-10 as there is already a category that includes 5?

     

    Age Bins =
    SWITCH (
        TRUE (),
        ISBLANK ( 'Legal Files'[Child Age] )
            || 'Legal Files'[Child Age] = 0, "0",
        'Legal Files'[Child Age] < 1, "<1",
        'Legal Files'[Child Age] <= 5, "1-5",
        'Legal Files'[Child Age] <= 10, "6-10",
        'Legal Files'[Child Age] > 10, "Older than 10"
    )
    

     

     

  • Hi inglexjc,

    using the filw that v-hjannapu attached, I see this if I turn the graph into a  table visual

     

     

    Age 0 is included and considered and all the children (7 rows) are shown

     

    If you still have issues, the only way to fix it is that you share some of your data so we check if there is any anomaly. Please anyway make sure to check the result as a table visual and only after as a graph

     

    If you have already done this and I missed the thing, apologies, just please send here the link to your data. We need to fix the thing on your semantic model in my opinion

     

    If this helped, please consider giving kudos and mark as a solution

    @me in replies or I'll lose your thread

    Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

    Consider voting this Power BI idea

    Francesco Bergamaschi

    MBA, M.Eng, M.Econ, Professor of BI

20 Replies

  • Hi inglexjc 

    I would check the data type of the age column Child Age

     

    is it of what data type (not format, data type)

     

    PS you need to change this condition

     

    'Legal Files'[Child Age]>=10, "Older than 10"

     

    to

     

    'Legal Files'[Child Age]>10, "Older than 10"

     

    as the 10 is included in the previous condition. This has nothing to do with your issue but sine I've seen it I write it

     

     

     

    If this helped, please consider giving kudos and mark as a solution

    @me in replies or I'll lose your thread

    Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

    Consider voting this Power BI idea

    Francesco Bergamaschi

    MBA, M.Eng, M.Econ, Professor of BI

    • inglexjc's avatar
      inglexjc
      Post Patron

      Thank you I fixed the >10.

       

      The data type for Child Age is Whole Number:

       

       

      For Age Bins is TEXT (I just tried to change to whole number and it gave me an error)

       

       

      What do I need to fix to get all the age 0 to show and those age 1 to show correctly?

      • FBergamaschi's avatar
        FBergamaschi
        Super User

        At this point, please paste here the table so I can import it and apply your code

         

        Do not paste an image, please, but the data in a way I can copy and paste

         

        You cannot chenge the type to  whole numbers as Age Bins is a text "1-5" for example

         

        If this helped, please consider giving kudos and mark as a solution

        me in replies or I'll lose your thread

        Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

        Consider voting this Power BI idea

        Francesco Bergamaschi

        MBA, M.Eng, M.Econ, Professor of BI

  • The formula looks ok so something else is causing the issue

     

    Pls only paste the childage column do I can help you

    • inglexjc's avatar
      inglexjc
      Post Patron

      I deleted all the PPI data to give Child DOB, how I'm fiquring out child age.  I can't fiqure out how to send you the PowerBI Desktop data for you to reivew.

  • As per your condition, Age 0 is <1 as you used <=1 instead of <1.  Also, shouldn't it be 6-10 instead of 5-10 as there is already a category that includes 5?

     

    Age Bins =
    SWITCH (
        TRUE (),
        ISBLANK ( 'Legal Files'[Child Age] )
            || 'Legal Files'[Child Age] = 0, "0",
        'Legal Files'[Child Age] < 1, "<1",
        'Legal Files'[Child Age] <= 5, "1-5",
        'Legal Files'[Child Age] <= 10, "6-10",
        'Legal Files'[Child Age] > 10, "Older than 10"
    )
    

     

     

    • inglexjc's avatar
      inglexjc
      Post Patron

      Thank you for this.  I put in exactly what you did and 0 is still missing.  8/5 should have 2 kids age 0 and the graph using the Age Bin's is not showing them.

       

       

  • v-hjannapu's avatar
    v-hjannapu
    Community Support

    Hi inglexjc,

    Thank you  for reaching out to the Microsoft fabric community forum.

     

    I would also take a moment to thank danextiangmsambornFBergamaschi  for actively participating in the community forum and for the solutions you have been sharing in the community forum. Your contributions make a real difference.
    I tried this practically and the updated age bin logic works as expected  all age groups including age 0 are now showing correctly in the chart.
    Please find the attached pbix file for your reference 

    Hope this helps if you have any queries we are  happy to assist you further.
    Best Regards,
    Harshitha.

    • inglexjc's avatar
      inglexjc
      Post Patron

      Thank you for this.  I used exactly what you used, and Age 0 is still missing.  See 8/5 should have at least 2 kids age 0 and none are showing in the graph.

       

       

      • FBergamaschi's avatar
        FBergamaschi
        Super User

        Hi inglexjc,

        using the filw that v-hjannapu attached, I see this if I turn the graph into a  table visual

         

         

        Age 0 is included and considered and all the children (7 rows) are shown

         

        If you still have issues, the only way to fix it is that you share some of your data so we check if there is any anomaly. Please anyway make sure to check the result as a table visual and only after as a graph

         

        If you have already done this and I missed the thing, apologies, just please send here the link to your data. We need to fix the thing on your semantic model in my opinion

         

        If this helped, please consider giving kudos and mark as a solution

        @me in replies or I'll lose your thread

        Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

        Consider voting this Power BI idea

        Francesco Bergamaschi

        MBA, M.Eng, M.Econ, Professor of BI