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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

How to use an IF statement measure in a BarChart?

I do not want to add calculated columns or tables to the model.

I have this DAX:

    IF(
        COUNTROWS(
            FILTER(
                table,
                table[column] = "xyz"
                && table[ID] = SELECTEDVALUE(dim_id[ID])
            )
        ) > 0,
        1,
        0
    )
 
This works when I put it in a table. But I also want to show the count in a bar chart grouped by other columns.
 
Thanks
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you Ashish_Mathur and Shravan133

Hi, @Anonymous 

Based on your description, I've created the following sample data:

vjianpengmsft_0-1726211868993.png

I use the following DAX expression to get the count:

Count = 
        COUNTROWS(
            FILTER(
                'Table',
                'Table'[column]="xyz"&&
                 'Table'[ID] IN VALUES(dim_id[ID])
            )
        ) 

Create a slicer using dim_id[ID]. Create a bar chart using the group and count Measure:

vjianpengmsft_1-1726211987347.png

vjianpengmsft_2-1726212010409.png

I've provided the PBIX file used this time below.

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you Ashish_Mathur and Shravan133

Hi, @Anonymous 

Based on your description, I've created the following sample data:

vjianpengmsft_0-1726211868993.png

I use the following DAX expression to get the count:

Count = 
        COUNTROWS(
            FILTER(
                'Table',
                'Table'[column]="xyz"&&
                 'Table'[ID] IN VALUES(dim_id[ID])
            )
        ) 

Create a slicer using dim_id[ID]. Create a bar chart using the group and count Measure:

vjianpengmsft_1-1726211987347.png

vjianpengmsft_2-1726212010409.png

I've provided the PBIX file used this time below.

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Ashish_Mathur
Super User
Super User

Hi,

Simplify the measure to

= calculate(COUNTROWS(table),table[column] = "xyz")

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Shravan133
Super User
Super User

try this:

Measure_Count_XYZ =
CALCULATE(
COUNTROWS(
FILTER(
table,
table[column] = "xyz"
&& table[ID] = SELECTEDVALUE(dim_id[ID])
)
)
)

  • Now, use Measure_Count_XYZ in the Values section of the bar chart.
  • For the Axis, group by any columns you want, such as other dimensions or categories.

This will now dynamically calculate and display the count of rows where table[column] = "xyz" and table[ID] = SELECTEDVALUE(dim_id[ID]) in the context of the chart, grouping by whatever columns you place in the visual.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors