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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
bhavinshah
Frequent Visitor

Group by with If Condition

Hello Team,

I have this table (Col A and Col B) and I need Output like this in Col F, G, H. 

Please help me with Power BI. 

bhavinshah_0-1709406719891.png

 

2 ACCEPTED SOLUTIONS
Musadev
Resolver III
Resolver III

Hi @bhavinshah 
You can use 2 measures for the new columns. check the output first and then try the DAX code for measures.
TBL7 is my table name.

Musadev_0-1709407985143.png

First measure the count all the values (Y and N both)

TBL7 Total Count = COUNTROWS(TBL7)

After that filter out the Y rows and then count the rows.

TBL7 Count Y = 
VAR ValuesY =
FILTER(
    TBL7,
    TBL7[Status] = "Y"
)
VAR ValuesCount =
COUNTROWS(ValuesY)
RETURN
ValuesCount+0

View solution in original post

Kobe100
Frequent Visitor

Dear @bhavinshah ,

Please find below a possible solution.

This measure is for the Group measure.

Group =
COUNTROWS('My table')

 

This is for the Count measure.

Count =
VAR selItem = SELECTEDVALUE('My table'[Status])

VAR Yes_ =
IF(
    selItem = "N",
    0,
    CALCULATE(
        COUNTROWS('My table'),
        FILTER('My table',
        'My table'[Status] = "Y"))
)
RETURN

Yes_
Result.png
 
*****Please accep this as a solution****

View solution in original post

6 REPLIES 6
bhavinshah
Frequent Visitor

Hello @Musadev  @Kobe100 

 

Thanks for helping. Both solutions are working properly. 

Kobe100
Frequent Visitor

Dear @bhavinshah ,

Please find below a possible solution.

This measure is for the Group measure.

Group =
COUNTROWS('My table')

 

This is for the Count measure.

Count =
VAR selItem = SELECTEDVALUE('My table'[Status])

VAR Yes_ =
IF(
    selItem = "N",
    0,
    CALCULATE(
        COUNTROWS('My table'),
        FILTER('My table',
        'My table'[Status] = "Y"))
)
RETURN

Yes_
Result.png
 
*****Please accep this as a solution****
Musadev
Resolver III
Resolver III

Hi @bhavinshah 
You can use 2 measures for the new columns. check the output first and then try the DAX code for measures.
TBL7 is my table name.

Musadev_0-1709407985143.png

First measure the count all the values (Y and N both)

TBL7 Total Count = COUNTROWS(TBL7)

After that filter out the Y rows and then count the rows.

TBL7 Count Y = 
VAR ValuesY =
FILTER(
    TBL7,
    TBL7[Status] = "Y"
)
VAR ValuesCount =
COUNTROWS(ValuesY)
RETURN
ValuesCount+0

Hello @Musadev 

 

I need to do Group by Count first.

 

bhavinshah_0-1709408523003.png

 

Then I need to following the Data. 

 

bhavinshah_1-1709408594132.png

Thanks 

The first measure has grouped all the data irrespective of the status (Y,N)
and then it applied a check to count only the Y status and ignore the N.
You can add another measure as well to count the N values for each text, and then minus it from the total count and it will give you the same results. 

Hello @Musadev 

This works - 

TBL7 Total Count = COUNTROWS(TBL7)

 Original 

bhavinshah_0-1709409320710.png

Now how can I apply Y then Count should be there Else 0   - How CAn I apply  

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.