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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
inglexjc
Post Patron
Post Patron

Color coding graph based on age.

I was able to get a new table created to group children by ages.

 

inglexjc_0-1673884433161.png

 

and was told to create the following measure 

 

Count Age =
VAR __AgeBandMin = SELECTEDVALUE('Query1'[Min] )
VAR __AgeBandMax = SELECTEDVALUE('Query1'[Max])
return
CALCULATE(
    COUNT('Legal Files'[Age]),
    'Legal Files'[Age] >= __AgeBandMin,
    'Legal Files'[Age] <= __AgeBandMax
)
 
But I can't get a graph to create based on ages and being color coded like this:
inglexjc_1-1673884486292.png

 

2 ACCEPTED SOLUTIONS

Hi @inglexjc @amitchandak ,
Just replace the comma with && 'Legal Files'[Age] >= __AgeBandMin &&.

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




View solution in original post

@Nathaniel_C  don't worry about it I went a different direction since it wasn't working.

View solution in original post

11 REPLIES 11
amitchandak
Super User
Super User

@inglexjc , try like

Count Age =
VAR __AgeBandMin = SELECTEDVALUE('Query1'[Min] )
VAR __AgeBandMax = SELECTEDVALUE('Query1'[Max])
return
CALCULATE(
COUNTX(Filter('Legal Files',
'Legal Files'[Age] >= __AgeBandMin,
'Legal Files'[Age] <= __AgeBandMax
),'Legal Files'[Age]) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  I get error:

inglexjc_0-1673889023195.png

 

Hi @inglexjc @amitchandak ,
Just replace the comma with && 'Legal Files'[Age] >= __AgeBandMin &&.

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




@Nathaniel_C  which comma.  If I use:

Count Age =
VAR __AgeBandMin = SELECTEDVALUE('Query1'[Min] )
VAR __AgeBandMax = SELECTEDVALUE('Query1'[Max])
return
CALCULATE(
COUNTX(Filter('Legal Files' &&
'Legal Files'[Age] >= __AgeBandMin,
'Legal Files'[Age] <= __AgeBandMax
),'Legal Files'[Age]) )
I get this error: inglexjc_0-1673896817794.png

If I use:

Count Age =
VAR __AgeBandMin = SELECTEDVALUE('Query1'[Min] )
VAR __AgeBandMax = SELECTEDVALUE('Query1'[Max])
return
CALCULATE(
COUNTX(Filter('Legal Files'&,
'Legal Files'[Age] >= __AgeBandMin &&
'Legal Files'[Age] <= __AgeBandMax
),'Legal Files'[Age]) )
I get this error:
inglexjc_1-1673896866733.png

And if I use this code: 

Count Age =
VAR __AgeBandMin = SELECTEDVALUE('Query1'[Min] )
VAR __AgeBandMax = SELECTEDVALUE('Query1'[Max])
return
CALCULATE(
COUNTX(Filter('Legal Files'&,
'Legal Files'[Age] >= __AgeBandMin,
'Legal Files'[Age] <= __AgeBandMax
)&&'Legal Files'[Age]) )
I get this error:
inglexjc_2-1673896920768.png

 

Hi @inglexjc @amitchandak ,
You left an extra & between the first time and the second time.

Count Age =
VAR __AgeBandMin =
    SELECTEDVALUE ( 'Query1'[Min] )
VAR __AgeBandMax =
    SELECTEDVALUE ( 'Query1'[Max] )
RETURN
    CALCULATE (
        COUNTX (
            FILTER (
                'Legal Files',
                'Legal Files'[Age] >= __AgeBandMin
                    && 'Legal Files'[Age] <= __AgeBandMax
            ),
            'Legal Files'[Age]
        )
    )

 Try above.

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
 





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

Proud to be a Super User!




So I think the new measure worked, no error but how to do I get the data to show on the graph?  The graph right now show blank when I have the Count Measure selected and the Court dates.

 

inglexjc_0-1673899531250.png

 

@Nathaniel_C 

So I think the new measure worked, no error but how to do I get the data to show on the graph?  The graph right now show blank when I have the Count Measure selected and the Court dates.

 

inglexjc_0-1673968905159.png

 

 

Hi @inglexjc ,
I would be glad to help you.  However, I was just responding to the syntax in the measure so that it would run.  You said it does now.  This is a little complicated because you said that you were told to run a certain measure.  Since we don't see the original question that you posted, it hard to say what the issue is.

I am work, but will look at this as I can. Two things, check to see if the data is coming in by returning the variables (VAR) and seeing if you are actually getting anything. You can then post the measure to a card.

Count Age Test=
VAR __AgeBandMin =
    SELECTEDVALUE ( 'Query1'[Min] )
VAR __AgeBandMax =
    SELECTEDVALUE ( 'Query1'[Max] )
Return _AgeBandMin //Then try with the other one.

Next, give us the link to the original question that you posted.


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




@Nathaniel_C when I use a card and the measure it comes out blank.

 

My original question link is here: https://community.powerbi.com/t5/Desktop/Creating-Range-for-Age-Groups/m-p/3017511#M1028489

 

This is where I was told how to create a table to get the ages grouped and then to create the meausre that wasn't working.  And looks like still isn't working.  But my end goal is to get a color coded graph based on ages.  See picture in my oringal quesiton and the start of this thread.

 

Legal Files is my pain Table.  Caseworker and Query 1 was build from Legal Files.  Query 1 is where the Age table and the measure are currently located.

 

inglexjc_0-1673970621694.png

 

Hi @inglexjc ,
Will look at your original file.
Nathaniel





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

Proud to be a Super User!




@Nathaniel_C  don't worry about it I went a different direction since it wasn't working.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.